الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مالذى ينقص هذا البرنامج لكى يعمل

مغلق
بدأه microsmart1 في 21 نوفمبر 2006 · 2 رد · 666 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

يجماعة انا جبت كود جاهز لبرنامج الرسام من موقع اكواد مجانية

بس الكود بدون دالة ال main

وبما انى مبتدء لسه ومعرفش شكل اى برنامج

فيريت تساعدونى اعرف دالة ال main بتاعة البرنامج ده هيتكتب فيها ايه

وايه اللى ناقص البرنامج علشان يشتغل

/************************************************************************************
* This is a simple Java paint program demonstrating AWT's 3D mouseDrag() options.   *
* GUI improvements such as more AutoDraw options are in the making.				 *
* Features include:																 *
*	 1. Adjustable width and height												*
*	 2. Customizable brush and brush colors										*
*	 3. Auto draw feature - currently draws default with the fill3DRect			*
* If you have Microsoft's Java VM 1.5.1, I've created an .exe of this program	   *
* that runs as a stand-alone application.										   *
*																				   *
* Author: Aaron Collins															 *
* Email: acorn71@gmail.com														  *
*************************************************************************************/


import java.awt.*;
import java.applet.Applet;

public class JavaDraw extends Applet {
	private Choice shapeButton, colorButton;
	private int xValue, yValue, w, h;
	private int randomColor, direction, rxy, distance;
	private boolean firstTime;
	private Button sizeButton, eraserButton, autoDesignButton;
	private TextField input1, input2;
	private Label help, prompt1, prompt2;
	private Panel p1, p2;
	private Color c;

	public void init() {	
		setBackground( Color.white );
		w = 10;
		h = 10;
		firstTime = true;
		c = Color.gray;
		shapeButton = new Choice();
		colorButton = new Choice();
		setLayout( new FlowLayout( FlowLayout.LEFT, 15, 15 ) );
		p1 = new Panel();
		p2 = new Panel();
		p1.setBackground( Color.lightGray );
		p2.setBackground( Color.lightGray );
		p1.add( prompt1 = new Label( "Width" ) );
		p2.add( prompt2 = new Label( "Height" ) );

		colorButton.addItem( "Gray" );
		colorButton.addItem( "Magenta" );
		colorButton.addItem( "Green" );
		colorButton.addItem( "Orange" );
		colorButton.addItem( "Yellow" );
		colorButton.addItem( "Blue" );
		colorButton.addItem( "Red" );
		colorButton.addItem( "Cyan" );
		colorButton.addItem( "Black" );
		colorButton.addItem( "Pink" );
		shapeButton.addItem( "3D Square (light)" );
		shapeButton.addItem( "3D Square (dark)" );
		shapeButton.addItem( "Round Brush" );
		shapeButton.addItem( "Sqare Brush" );
		shapeButton.addItem( "Draw Arc Angle" );
		shapeButton.addItem( "Fill Arc Angle" );

		add( p1 );
		add( input1 = new TextField( "10", 3 ) );
		add( p2 );
		add( input2 = new TextField( "10", 3 ) );
		add( sizeButton = new Button( "Change size" ) );		
		add( colorButton );
		add( shapeButton );
		add( eraserButton = new Button( "Eraser" ) );
		add( autoDesignButton = new Button( "Auto Design" ) );

	}

	public void paint( Graphics g ) {

	  if ( !firstTime ) {

		g.setColor ( c );

		switch ( shapeButton.getSelectedIndex() ) {

		  case 0: g.fill3DRect( xValue, yValue, w, h, true ); break;
		  case 1: g.fill3DRect( xValue, yValue, w, h, false ); break;
		  case 2: g.fillOval( xValue, yValue, w, h ); break;
		  case 3: g.fillRect( xValue, yValue, w, h ); break;
		  case 4: g.drawArc( xValue, yValue, w, h, 0, 180 ); break;
		  case 5: g.fillArc( xValue, yValue, w, h, 0, 180 ); break;
		  default: g.fillOval( xValue, yValue, w, h );
		}
	  }
	}

	// override Component class update
	public void update ( Graphics g ) {
	  // do not clear background; only call paint
	  paint( g );
	}

	public boolean mouseDrag( Event e, int x, int y ) {	
	  xValue = x;
	  yValue = y;

	  repaint();

	  // enable drawing
	  firstTime = false;

	  showStatus( "Painting started." );

	  return true;   // event handled 
	}

	public boolean action( Event e, Object o ) {

	  Graphics g = getGraphics();

	  if( e.target == sizeButton ) {

		try {
			widthResize();
		} catch( NumberFormatException exception ) { 
			showStatus( "Please enter values in the width field (default is 10)" );
		}

		try { 
			heightResize();
		} catch( NumberFormatException exception ) {
			showStatus( "Please enter values in the height field (default is 10)" ); 
		}
	}

	switch ( colorButton.getSelectedIndex() ) {
		case 0: c = Color.gray; break;
		case 1: c = Color.magenta; break;
		case 2: c = Color.green; break;
		case 3: c = Color.orange; break;
		case 4: c = Color.yellow; break;
		case 5: c = Color.blue; break;
		case 6: c = Color.red; break;
		case 7: c = Color.cyan; break;
		case 8: c = Color.black; break;
		case 9: c = Color.pink; break;
		default: c = Color.black;
	}

	if ( e.target == eraserButton ) {
		c = Color.white;
		shapeButton.select( 3 );
	}

	if ( e.target == autoDesignButton ) {
		xValue = 400;
		yValue = 200;

		for ( int count = 0; count <= 100; count++ ) {			
			g.setColor( c );
			rxy = 0 + ( int ) ( Math.random() * 8 ); 
			distance = 0 + ( int ) ( Math.random() * 50 ); 

		  switch ( rxy ) {
			case 0:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue -= 3;
				yValue += 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  } 
			  break;

			case 1:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue += 3;
				yValue -= 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  }
			  break;

			case 2:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue -= 3;
				yValue -= 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  }
			  break;

			case 3:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				if ( xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0 ) {
				  xValue += 3;
				  yValue += 1;		
				  g.fill3DRect( xValue, yValue, w, h, true );
				}
			  }
			  break;

			case 4:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue -= 3;
				yValue += 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  }
			  break;				

			case 5:	
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue += 3;
				yValue -= 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  }
			  break;

			case 6:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue -= 3;
				yValue -= 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  }
			  break;

			case 7:
			  for ( int s1 = 0; s1 <= distance && xValue <= 800 && xValue > 0 && yValue <= 500 && yValue > 0; s1++ ) {
				xValue += 3;
				yValue += 1;		
				g.fill3DRect( xValue, yValue, w, h, true );
			  }
		  }			
		}
	  }
	  return true;
  }

  public void widthResize() throws NumberFormatException {
	w = Integer.parseInt( input1.getText() );
	if ( w == 0 ) throw new NumberFormatException();
  }

  public void heightResize() throws NumberFormatException {
	h = Integer.parseInt( input2.getText() );
	if ( h == 0 ) throw new NumberFormatException();
  }		

  public Color selectRandomColor() {
	randomColor = 0 + ( int ) ( Math.random() * 9 );

	switch ( randomColor ) {
	  case 0: c = Color.gray; break;
	  case 1: c = Color.magenta; break;
	  case 2: c = Color.green; break;
	  case 3: c = Color.orange; break;
	  case 4: c = Color.yellow; break;
	  case 5: c = Color.blue; break;
	  case 6: c = Color.red; break;
	  case 7: c = Color.cyan; break;
	  case 8: c = Color.black; break;
	  case 9: c = Color.pink; break;
	  default: c = Color.black;
	}
	return c;
  }

/*	
	// record x and y coordinates of mouse movement
	public boolean mouseMove( Event e, int x, int y ) {
	  showStatus( "mouse at (" + x + ", " + y + ")" );
	  return true;   // event has been handled
	} 
*/

}

لو جينا نعمل للبرنامج كومبايل هو مفيهوش اخطاء

بس لما نيجى نعمل رن هيعطى اكسبشن علشان دالة المين مش موجودة

انا عاوز اعرف دالة المين هنا هيتكتب فيها ايه بالظبط علشان انا عمرى ما عملت برنامج قبل كده

#2

السلام عليكم

أخي هناك نوعين من البرامج التي بامكانك برمجتها في الجافا

Application and Applet

الفرق أن Applet باستطاعتك تحميله على صفحة الويب واستعراضه على الانترنت

Application هي البرامج العاديه التي تراها في كل مكان وتشتغل على كمبيوتر المبرمج نفسه

برنامجك هو Applet

لاحظ معي

public class JavaDraw extends Applet

لكي تعمل Applet يجب عليك ان ترث الفئه Applet or JApplet

لايحتاج إلى دالة main فقط يحتاج أن تعرف مشروعك على إنه Java Applet وليس Java Application

وسينفذ باذن الله

تم تعديل هذه المشاركة بواسطة {عيسى} في 21 نوفمبر 2006 في 18:44

#3

برامج الابلت لا تحتاج الى الطريقة main

ويمكنك رؤية خرج البرنامج باستخدام مستعرض الانترنت IE

ضع الشفرها لتالي في ملف بأمتداد html و اجعلها في ملف واحد مع الكلاس JavaDraw

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Applet a</title>
</head>
<body>
<applet CODE=JavaDraw.class width=600 height=600></applet>
</body>
</html>

هذا الموضوع مغلق.

مواضيع مشابهة