Hey guys,
So I've designed a simple converter that has 4 buttons and 5 labels on the main frame which invoke a series of converters. The weird thing is that after I export the classes to a .jar file and run the jar the labels and buttons will randomly not load or won't load until I mouse over them and other times it will load fine. I'm wondering if I have something in the wrong location on the main class. Here is the main frame code.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import converters.FrameClass;
import converters.KGConverterClass;
import converters.MilesFeet;
import converters.YardstoMeters;
public class FirstFrame {
//ActionListener for the yards to Meters
static class Action4 implements ActionListener{
public void actionPerformed (ActionEvent e){
YardstoMeters open = new YardstoMeters();
open.Converter4();
}
}
//ActionListener for the miles to feet
static class Action3 implements ActionListener{
public void actionPerformed (ActionEvent e){
MilesFeet open = new MilesFeet();
open.Converter3();
}
}
//ActionListener for the FT to CM converter
static class Action implements ActionListener{
public void actionPerformed (ActionEvent e){
FrameClass open = new FrameClass();
open.Converter1();
}
}
//ActionListener for the KG to LB converter
static class Action2 implements ActionListener{
public void actionPerformed (ActionEvent e){
KGConverterClass open = new KGConverterClass();
open.Converter2();
}
}
//ActionListener that EXITS the program
static class ActionExit implements ActionListener{
public void actionPerformed (ActionEvent e){
System.exit(0);
}
}
public static void main(String[] args) {
//frame and menu bar
JFrame frame = new JFrame("Lane's Converter");
frame.setVisible(true);
frame.setSize(400,350);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("File");
mb.add(file);
JMenu about = new JMenu("About");
mb.add(about);
JMenuItem exit = new JMenuItem("Exit");
exit.addActionListener(new ActionExit());
file.add(exit);
frame.setJMenuBar(mb);
JPanel panel = new JPanel();
panel.setLayout(null);
frame.add(panel);
JLabel mainlabel = new JLabel("Choose a Converter");
mainlabel.setBounds(120,10,200,20);
panel.add(mainlabel);
//Buttons and Labels for the main frame
JButton button1 = new JButton("Run");
button1.addActionListener(new Action());
button1.setBounds(200,50,60,23);
panel.add(button1);
JLabel l1 = new JLabel("FT to CM");
l1.setBounds(90,50,100,23);
panel.add(l1);
JButton button2 = new JButton("Run");
button2.addActionListener(new Action2());
button2.setBounds(200,100,60,23);
button2.setLayout(null);
panel.add(button2);
JLabel l2 = new JLabel("KG to LB");
l2.setBounds(90,100,100,23);
panel.add(l2);
JButton button3 = new JButton("Run");
button3.addActionListener(new Action3());
button3.setBounds(200,150,60,23);
button3.setLayout(null);
panel.add(button3);
JLabel l3 = new JLabel("Miles to Feet");
l3.setBounds(90,150,120,23);
panel.add(l3);
JButton button4 = new JButton("Run");
button4.addActionListener(new Action4());
button4.setBounds(200,200,60,23);
button4.setLayout(null);
panel.add(button4);
JLabel l4 = new JLabel("Yards to Meters");
l4.setBounds(90,200,150,23);
panel.add(l4);
}
}