Input/Output program Compiles but doesn't run
- From: "janicethorne via JavaKB.com" <u16040@uwe>
- Date: Thu, 30 Mar 2006 15:58:39 GMT
Can anyone help me with this error? I have included the code after the
explaination.
This code uses the rectangle class (which I just included in the code,
although I was supposed to import it). The code should take in values from
the user, calculate them using the methods stored in the rectangle class, and
display them in the GUI. I was able to get my code to compile, but when it
runs, I get "Exception in thread "main" java.lang.NoSuchMethodError: main. I
have been over and over the code. I can't see what I'm doing wrong. If you
can help in any way, I would really appreciate it. I think I included
everything I was supposed to, but I am a beginner and can't always tell if I
need more. Any help will be appreciated. thank you.
import java.text.*;
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Program81 {
JFrame outputFrame;
JLabel enterWidth;
JLabel enterLength;
JLabel calculateArea;
JLabel calculatePerim;
JTextField dataWidth;
JTextField dataLength;
JButton calculate;
JButton clear;
ButtonHandler button;
private class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
rectangle r = new rectangle();
r.setWidth(Integer.parseInt(dataWidth.getText()));
r.setLength(Integer.parseInt(enterLength.getText()));
calculateArea.setText("The area of your rectangle is " + r.calcArea());
calculatePerim.setText("The perimeter of your rectangle is " + r.
calcPerimeter());
}
}//end of action handler
public void main ( String args[] ) throws IOException {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
//Declare a class JFrame variable
outputFrame = new JFrame();
//Declare a container variable
Container outputPane;
outputPane = outputFrame.getContentPane();
//default close action
outputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//default size
outputFrame.setSize(300, 300);
//set class flow layout argument
outputPane.setLayout(new FlowLayout());
//create components
enterWidth = new JLabel("Enter Width");
enterLength = new JLabel("Enter Length");
calculateArea = new JLabel("");
calculatePerim = new JLabel("");
dataWidth = new JTextField(15);
dataLength = new JTextField(15);
calculate = new JButton("Calculate");
clear = new JButton("Clear fields");
button = new ButtonHandler();
calculate.addActionListener(button);
//add components to the frame
outputPane.add(BorderLayout.WEST, enterWidth);
outputPane.add(BorderLayout.EAST, dataWidth);
outputPane.add(BorderLayout.WEST, enterLength);
outputPane.add(BorderLayout.EAST, dataLength);
outputPane.add(BorderLayout.SOUTH, calculate);
outputPane.add(BorderLayout.SOUTH, clear);
outputPane.add(BorderLayout.SOUTH, calculateArea);
outputPane.add(BorderLayout.SOUTH, calculatePerim);
// make visible
outputFrame.setVisible(true);
}//end of main
public class rectangle {
private int length;
private int width;
public rectangle() {
length = 1;
width = 1;
}
public rectangle(int l, int w){
length = l;
width = w;
}
public int calcArea() {
int area = length * width;
return area;
}
public int calcPerimeter() {
int perimeter = 2 * (length + width);
return perimeter;
}
public void setWidth(int w1) {
if (w1 >= 1 && w1 <= 20)
width = w1;
else
width = 1;
}
public void setLength(int l1) {
if (l1 >= 1 && l1 <= 20)
length = l1;
else
length = 1;
}
public int getWidth() {
return width;
}
public int getLength() {
return length;
}
}//end of rectangle class
}//end of program81
--
Message posted via http://www.javakb.com
.
- Follow-Ups:
- Re: Input/Output program Compiles but doesn't run
- From: Carl
- Re: Input/Output program Compiles but doesn't run
- From: Roedy Green
- Re: Input/Output program Compiles but doesn't run
- Prev by Date: Add an actionListener ActionEvent in jsp
- Next by Date: Re: Add an actionListener ActionEvent in jsp
- Previous by thread: Add an actionListener ActionEvent in jsp
- Next by thread: Re: Input/Output program Compiles but doesn't run
- Index(es):