Help me guys..im trying to make event handling for button "Report" to display Value and Result on another window...
i dont know what the problem...~ help me guys..
and can someone teach me how to do the meter to kilometer if i press "Convert" button..
p/s : sry for my bad english
Converter.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Converter extends JFrame implements ActionListener{
private JLabel jlbValue, jlbResult;
private JTextField jtfValue, jtfResult;
private JButton jbtConvert, jbtReport;
public Converter (){
JPanel p1 = new JPanel();
p1.setLayout (new GridLayout (2,2,2,5));
p1.add(jlbValue = new JLabel ("Value"));
p1.add(jtfValue = new JTextField (3));
p1.add(jlbResult = new JLabel ("Result"));
p1.add(jtfResult = new JTextField (3));
jtfResult.setEditable(false);
JPanel p2 = new JPanel ();
p2.setLayout (new FlowLayout());
p2.add (jbtConvert = new JButton ("Convert"));
p2.add (jbtReport = new JButton ("Report"));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1, BorderLayout.CENTER);
getContentPane().add(p2, BorderLayout.SOUTH);
jbtConvert.addActionListener(this);
jbtReport.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if((e.getSource() == jbtReport)) {
String Value = jtfValue.getText();
int Result = (Integer.parseInt(jtfResult.getText().trim()));
Report frame = new Report(Value,String.valueOf(Result));
frame.setSize(300,200);
frame.setTitle("PassingReport");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
}
public static void main(String[]args){
Converter frame = new Converter();
frame.setDefaultCloseOperation(3);
frame.setTitle("Converter");
frame.setSize(300,200);
frame.setVisible(true);
frame.setLocationRelativeTo (null);
}
}
Report.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Report extends JFrame {
private JLabel jlbValue, jlbResult;
public Report (){
}
public Report (String Value, String Result) {
JPanel p1 = new JPanel ();
p1.setLayout (new GridLayout (2,2,2,5));
p1.add (jlbValue = new JLabel ("The Value you entered:" +Value));
p1.add (jlbResult = new JLabel ("Result:" +Result));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.SOUTH);
}
public static void main(String[] args) {
//Create a frame
Report frame = new Report();
frame.setSize(300,200);
frame.setTitle("PassingReport");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}