JLabel and text concept issues
Basically I want to display the output with a JLabel from the text fields where the data is entered, and when the Calculate button is pressed to display this output. Here is what I have so far but I feel I'm kind of off track a bit.
###################
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TextFrame extends JFrame implements ActionListener{
private static final int FRAME_WIDTH = 300;
private static final int FRAME_HEIGHT = 200;
private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 250;
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;
private static final double SHIPPING = 0.12;
private JButton calculateTotal;
private JLabel prompt;
private JLabel prompt2;
private JLabel display;
private JLabel display2;
private JTextField inputLine;
private JTextField inputLine2;
private JTextField inputLine3;
public static void main(String[] args) {
TextFrame frame = new TextFrame();
frame.setVisible(true);
}
public TextFrame() {
Container contentPane;
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setResizable(false);
setTitle("Project");
setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
prompt = new JLabel( );
prompt.setText("Enter ID Code: ");
prompt.setSize(150,25);
contentPane.add(prompt);
inputLine = new JTextField( );
inputLine.setColumns(10);
contentPane.add(inputLine);
prompt2 = new JLabel( );
prompt2.setText("Weight: Pounds | Ounces: ");
prompt2.setSize(150,25);
contentPane.add(prompt2);
inputLine2 = new JTextField( );
inputLine2.setColumns(5);
contentPane.add(inputLine2);
inputLine3 = new JTextField( );
inputLine3.setColumns(5);
contentPane.add(inputLine3);
inputLine.addActionListener(this);
inputLine2.addActionListener(this);
inputLine3.addActionListener(this);
calculateTotal = new JButton("Calculate");
calculateTotal.setSize(BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(calculateTotal);
display = new JLabel( );
display.setText(" ID Weight Shipping Charge ");
display.setSize(150,25);
contentPane.add(display);
String idcode = inputLine.getText();
String pounds = inputLine2.getText();
String ounces = inputLine3.getText();
display2 = new JLabel( );
display2.setText(idcode);
display2.setSize(150,25);
contentPane.add(display2);
calculateTotal.addActionListener(this);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() instanceof JButton) {
JButton clickedButton = (JButton) event.getSource();
} else {
setTitle("You entered '" + inputLine.getText() + "'");
}
}
}
Any Help would be very much appreciated.
Thanks,
- GoOsE