Leo
Posts: 6
Nickname: dev313
Registered: Aug, 2002
|
|
Re: What is Graphics g?
|
Posted: Aug 14, 2002 10:44 AM
|
|
Ok, so this was part of an assingment. But I figured it out.
package homework9;
// Java core packages import java.awt.Graphics; // import class Graphics
// Java extension packages import javax.swing.*; // import package javax.swing
public class Homework9 extends JApplet {
// These are our A's...
int Side; // number of sides as an integer String strSide; // number of sides as a string // initialize applet by obtaining values from user public void init() { // obtain number of sides from user strSide = JOptionPane.showInputDialog( "Enter the number of sides" );
} // end method init
// draw results public void paint( Graphics g ) { String result; // the asterisk that we will paint // call inherited version of method paint super.paint( g ); result = squareOfAsterisks( strSide ); for ( int i = 1; i <= Side; i++ ){
g.drawString( result, 25, i * 25 );
} // end of for loop //JOptionPane.showMessageDialog(null, numSides, "Title",
JOptionPane.INFORMATION_MESSAGE); } // end method paint // our squareOfAsterisks Method... public String squareOfAsterisks( String x ) { int row = 1; int column = 1; String strOutPut; // our groups of asterisks strOutPut = ""; // initialize our output variable // convert numbers from type String to type double that the user entered Side = Integer.parseInt( x ); // print a row of 'Side' number of Asterisks... for ( row = 1; row <= Side; row++ ) { strOutPut += "* "; } // end for structure return strOutPut; } // end method squareOfAsterisks
} // end class AdditionApplet
|
|