• Post Reply Bookmark Topic Watch Topic
  • New Topic

classes

 
Thijs Haitema
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i have to make an applet for school with a two classes but it wont work. first I tried to do it without but my teacher didnt allowed it. I have to make an applet which can calculate how many apples can fit in a box, the variables are (length, width, height and the diameter of the apple)
this is what i first did:
some words are in dutch!!!
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Applet1 extends Applet {
TextField lengte, breedte, hoogte, appel;
int length, width, height, apple;
Button Knop;
public void init() {
setLayout( null );
setBackground( new Color(53,80,38));
setFont( new Font( "SansSerif", Font.BOLD, 14 ) );
setForeground( Color.red );
lengte = new TextField ();
lengte.setEditable( true );
lengte.setBounds( 100, 10, 80, 25 );
breedte = new TextField ();
breedte.setEditable( true );
breedte.setBounds( 100, 40, 80, 25 );
hoogte = new TextField ();
hoogte.setEditable( true );
hoogte.setBounds( 100, 70, 80, 25 );
appel = new TextField ();
appel.setEditable( true );
appel.setBounds( 100, 100, 80, 25 );
Knop = new Button ("Calculate");
Knop.setBounds( 300, 50, 80, 25 );
Knop.addActionListener( new KNOP() );
add( lengte );
add( breedte );
add( hoogte );
add( appel );
add( Knop );
}
class KNOP implements ActionListener {
public void actionPerformed( ActionEvent e ) {
String lengteInput = lengte.getText();
length = Integer.parseInt( lengteInput );
String breedteInput = breedte.getText();
width = Integer.parseInt( breedteInput );
String hoogteInput = hoogte.getText();
height = Integer.parseInt( hoogteInput );
String appelInput = appel.getText();
apple = Integer.parseInt( appelInput );
repaint();
}
}
void Appel( Graphics g ){
g.drawString( "One Apple measures: " +
Double.toString((Math.PI/6)*(apple*apple*apple)) + " cubic centimeters", 100 , 250 );
g.drawString("Diameter =", 20, 120 );
}
void Box(Graphics g ){
g.drawString( "Box content is: " + Integer.toString(length) + " x " +
Integer.toString(width) + " x " +
Integer.toString(height) + " = " +
Integer.toString(length * width * height) + " cubic centimeters", 100 , 200 );
g.drawString("Length =", 20, 30 );
g.drawString("Width =", 20, 60 );
g.drawString("Height =", 20, 90 );
}
public void paint( Graphics g ) {
Box (g);
Appel (g);
}
}
so please help me how I can convert this to an applet with two classes(box and appel)
Thijs
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!