I just created a swing GUI, but I can not get it to work! I pretty much am using all the same code format as the java.sun.com website....
Here it is:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class converterUND implements ActionListener {

JFrame frame;
JPanel panel;
JTextField textfield;
JButton getAnswer;
JLabel descriptionLabel, answerLabel;

public mainMultiplier(){
frame = new JFrame("Multiply a number by 2.");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(300, 40));
panel = new JPanel(GridLayout(2,2));

addObjects();

frame.getRootPane().setDefaultButton(getAnswer);
frame.getContentPane().add(panel, BorderLayout.CENTER);

frame.pack();
frame.setVisible(true);
}
private void addObjects(){
textfield = new JTextField(2);
descriptionLabel = new JLabel("Enter Number to be Multiplied", SwingConstants.LEFT);
getAnswer = new JButton("Multiply");
answerLabel = new JLabel("Answer:", SwingConstants.LEFT);

getAnswer.addActionListener(this);

panel.add(textfield);
panel.add(descriptionLabel);
panel.add(getAnswer);
panel.add(answerLabel);

descriptionLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
answerLabel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
}
public void actionPerformed(ActionEvent event) {
int IMPUT = (int)((Double.parseDouble(textfield.getText()))* 2.0);
answerLabel.setText("Answer: " + IMPUT);
}
private static void showGUI(){
converterUND NEW = new converterUND();
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
showGUI();
}
});
}
}
There is something wrong with this line:
Code:
public mainMultiplier(){
It says it has an invalid return value. What should I make it? I've tried void, but I'm assuming that's incorrect. Please help!