I am trying to make a GUI that does conversions. My first conversion will be Celsius to Fahrenheit and Fahrenheit to Celsius. I would like to use a Tabbed Frame similar to the code below:
TabbedPane
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class TabbedPane extends JFrame {
public TabbedPane() {
setTitle("Conversion Program");
JTabbedPane jtp = new JTabbedPane();
// JFrame frame = new JFrame();
getContentPane().add(jtp);
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();
JPanel jp4 = new JPanel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel();
JLabel label4 = new JLabel();
JTextField miles = new JTextField();
final JComponent[] inputs = new JComponent[]
{
new JLabel("Make"),
miles,
};
label1.setText("This program will convert measurements and distance from user input. Please select which tab you would like to enter data in."); // Label for About
label2.setText("Please enter how many Miles to convert to Kilometers."); // Label for Miles to Kilometers
label3.setText("Kilo to Mile"); // Label for Kilometers to Miles
label4.setText("Fah to Cel"); // Label for Fahrenheit to Celcius
jp1.add(label1);
jp2.add(label2);
jp3.add(label3);
jp4.add(label4);
jtp.addTab("About", jp1);
jtp.addTab("Miles to Kilometer", jp2);
jtp.addTab("Kilometers to Miles", jp3);
jtp.addTab("Fahrenheit to Celcius", jp4);
JButton test = new JButton("Convert");
//frame.add(jp1);
//frame.add(jp2);
jp2.add(test);
jp3.add(test);
ButtonHandler phandler = new ButtonHandler();
test.addActionListener(phandler);
}
class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "Your entered number KILOMETERS converts to MILES.", "Kilometer to Miles", JOptionPane. INFORMATION_MESSAGE);
}
}
public static void main(String[] args) {
TabbedPane tp = new TabbedPane();
tp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// tp.setVisible(true);
tp.setSize(800,800);
tp.setVisible(true);
}
}
I would to have a text box to enter a tempature and when you click the button it does the conversion.
How do i accomplish this?

New Topic/Question
Reply



MultiQuote




|