• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

classes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic