Java JFrame and JButton Help

Discussion in 'Silicon (v)Alley' started by MochaBearBlazed, Dec 7, 2014.

  1. #1 MochaBearBlazed, Dec 7, 2014
    Last edited by a moderator: Dec 7, 2014
    ive been trying to get underway on this program for my java class but i cant even get the first two elements to appear.  anyone know why my JFrame is blank? 
     
    edit: it looks like in the copy and past from Jgrasp the code got a little funky looking so be gentle.
     
     
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     

    public class TenNumbers
    {  
       
    public static void main(String [] args)
    {
    ManyNumbers mn = new ManyNumbers("To be Named Later - Program 6");
          
       }
    }
     
    class ManyNumbers extends JFrame
    {
    public static final int MAX_NUM = 10;
     
    JTextField [] nums = new JTextField[MAX_NUM];
    JButton newNums = new JButton("New Numbers");
       JTextField text1 = new JTextField();
      
      
    public ManyNumbers(String s)
    {
          
    super(s);
    setLayout(new FlowLayout());
          pack();
    setVisible(true);
         ;
          
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
     
     
    }

     
  2. I dont remember much from AWT / Swing coding, but it looks like you need to add the components to the frame using ManyNumbers.add(nums); and so on in the ManyNumbers method. I could be wrong, as I havent programmed AWT / Swing in years.
     

Share This Page