Help in running a Java program (no, it's not a school assignment)
#1
Hey,

I've been designing a Java program that simulates a lottery by accepting some input, such as the lowest number, the highest number, and the amount of numbers. Seems simple, right? Well, all was working well under a computer that uses Netbeans 7.01, until I tried to run it on a Linux Mint Machine that uses Netbeans 8.02

Here's what the original GUI was to look like:


[Image: picture.jpg]

But when I used other Java on other machines, this was the result:

[Image: Program.png]

On the Netbeans 7.01 computer, the JDK compiler version was 1.6.0_31-b05. The Netbeans 8.02 computer had the compiler 1.8.0_00. I don't know if that's the matter; maybe it is, but I might want a verification on that.

Here's the code. It's still unfinished, but that's not the problem.

Code:
//Name: RobertX

//Date: September 7, 2015
//Program Purpose: GUI that generates numbers based on user-input.

//Import class libraries
import javax.swing.*;              
import javax.swing.JOptionPane;              
import java.awt.*;     
import java.awt.event.*;
import java.awt.BorderLayout;

public class lottarygui     //Begin class
{
        //VARIABLES FOR DATA COLLECTION
        private JTextField lowerRange;
        private JTextField higherRange;
        private JTextField quantity;
        private JTextArea displayArea;
        
    public lottarygui()
    {        
        //ADD WARNING
        final String WARNING = "Please out valid data and not leave\n "
                               + "anything out. Also,do not enter any\n "
                               + "zeroes.";
        
        //WINDOW DESIGN
        
        //Frame settings
        JFrame jfrFrame = new JFrame("Lottary Program");
        jfrFrame.setSize(300,400);
        jfrFrame.setLocationRelativeTo (null);
        jfrFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jfrFrame.setVisible(true);
        jfrFrame.setResizable(false);
        
        //Panel to hold the user input controls in place
        JPanel jplInputs = new JPanel();
        jplInputs.setLayout(new GridLayout(4, 2));
        
        //CREATE INPUT CONTROLS
        
        //Lowest range
        JLabel jlblLowerRange = new JLabel("Lowest");
        lowerRange = new JTextField();
        
        //Highest range
        JLabel jlblHigherRange = new JLabel("Highest");
        higherRange = new JTextField();
        
        //Quantity
        JLabel jlblQuantity = new JLabel("Quantity");
        quantity = new JTextField();
        
        //Buttons and their respective action associations
        
        //Generate numbers button
        JButton jbtnGenerate = new JButton("Generate");
        ActionListener alGenerate = new listenGenerate();
        jbtnGenerate.addActionListener(alGenerate);
        
        //Reset all values button
        JButton jbtnReset = new JButton("Reset");
        ActionListener alReset = new listenReset();
        jbtnReset.addActionListener(alReset);        
        
        //ADD CONTROLS TO FORM
        jplInputs.add(jlblLowerRange);
        jplInputs.add(lowerRange);
        jplInputs.add(jlblHigherRange);
        jplInputs.add(higherRange);
        jplInputs.add(jlblQuantity);
        jplInputs.add(quantity);
        jplInputs.add(jbtnGenerate);
        jplInputs.add(jbtnReset);
        
        //CREATE DISPLAY AREA AND ADD
       
        //The display area used for showing generated numbers
        displayArea = new JTextArea();
        displayArea.setLineWrap(true);
        displayArea.setText(WARNING);
        
        //The control that sets autoscrolling for the display area
        JScrollPane jspDisplayArea = new JScrollPane(displayArea);
        jfrFrame.add(jspDisplayArea);
        
        //Add the JPanels to the window
        jfrFrame.add(jplInputs, BorderLayout.NORTH);
        jfrFrame.add(jspDisplayArea);

    }//END lottaryGUI constructor

    //MAIN Method
    public static void main (String[] args)
    {
        //CALL UP lottaryGUI CLASS
        new lottarygui();
    }//END Main method

    //GENERATE BUTTONS ACTION    
    private class listenGenerate implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            //DECLARE VARIABLES
            int low;
            int high;
            int qty;
            
            try
            {
                low =  Integer.parseInt(lowerRange.getText());
                high = Integer.parseInt(higherRange.getText());
                qty = Integer.parseInt(quantity.getText());                
            }
            catch (NumberFormatException nfe)
            {
                //RESET ALL FORM VALUES
                reset();
                
                //RESET VARIABLE VALUES
                low = 0;
                high = 0;
                qty = 0;                
            }//END format errors try-catch
            
            //CHECK IF PROGRAM CAN CONTINUE
            if (low != 0 || high != 0 || qty != 0)
            {
                
            }
            else
            {
                //ISSUE WARNING
                JOptionPane.showMessageDialog(null, "Please out valid data " +
                                                    " and not leave anything " +
                                                    "out. " +
                                                    "Also,do not enter any " +
                                                    "zeroes.");
              
            }//END IF continue CHECK
        }//END actionPerformed method
    }//END listenGenerate class

    //RESET ALL TEXT
    private class listenReset implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            //RESET ALL FORM VALUES
            reset();
        }//END actionPerformed method
    }//END listenGenerate class

    public void reset()
    {
        //RESET CONTROL VALUES
        lowerRange.setText("");
        higherRange.setText("");
        quantity.setText("");
        displayArea.setText("");
    }//END reset()
}//END lottarygui class

If there is something you can tell me, I will welcome it. Again, the code is incomplete, and I think I can take it from there.

Thank you for your attention.
Reply
#2
Not a Java programmer.

See if commenting the panel portion helps. Maybe some attrib has to be set (guessing).
Maybe comment the lottarygui() function and slowly open up the code.
Reply
#3
I got the thing working again.

I had to add the line,

[code]
jfrFrame.setVisible(true);
[/code

last in the order of appearance.

Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Java Course Materials RobertX 6 10,224 Sep 05, 2024, 02:36 am
Last Post: samui
  how can i learn to use Java efficiently Blue_Bon 10 12,210 Feb 26, 2024, 08:41 am
Last Post: RobertX
  Question About the Concept of Abstracts in Java RobertX 4 5,887 Jan 17, 2024, 07:50 am
Last Post: gulshan212
  [Release] OfflineBay v2 - Open source and No more Java dependency techtac 55 328,862 Apr 01, 2022, 13:42 pm
Last Post: UnknownIdot
  Regarding to Purpose for .class files in Java ankitdixit 1 11,811 Mar 10, 2022, 14:26 pm
Last Post: RobertX



Users browsing this thread: 1 Guest(s)