Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: buttons randomly show up in program

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default buttons randomly show up in program

    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);







    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: buttons randomly show up in program

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting

Similar Threads

  1. My bullseye won't show
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 30th, 2012, 07:33 PM
  2. Grid movement randomly not working
    By pajfilms in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 27th, 2011, 07:35 AM
  3. Threads are killed randomly in While true loop
    By kurt-hardy in forum Threads
    Replies: 7
    Last Post: August 11th, 2011, 07:55 AM
  4. thought i had it, then i sneezed and lost it (randomly generated numbers)
    By fakeClassy in forum Java Theory & Questions
    Replies: 13
    Last Post: July 17th, 2011, 04:16 PM
  5. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM