Thread: My message will not show up...

Results 1 to 8 of 8
  1. #1 My message will not show up... 
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    Here is my code:
    Code:
    package GUI;
    
    import java.awt.event.*;
    import javax.swing.*;
    import Core.Glass;
    import GUI.*;
    public class Actions implements ActionListener {
    	
    	public void actionPerformed(ActionEvent e) {
    		
    		Build build = new Build();
    		
    		String actionCommand = e.getActionCommand();
    		
    		String word = build.JTF.getText();
    		if (actionCommand.equals("Enter")) {
    			JOptionPane.showMessageDialog(null, word);
    		}
    
    	}
    }
    I don't see anything wrong with it, how come i can't see my code? Maybe it's thinking JTF is a method? That shouldn't be, when JTF is the textfield and it's grabbing text from it.

    Here is my build class:

    Code:
    
    package GUI;
    
    import java.awt.*;
    import javax.swing.*;
    import GUI.*;
    import Core.Glass;
    public class Build extends JFrame {
    	
    	private final int width = 250;
    	private final int height = 350;
    	JPanel panel1 = new JPanel();
    	JButton button1 = new JButton();
    	JLabel label1 = new JLabel();
    	JTextField JTF = new JTextField();
    	
    	/**
    	 * Creats a new JFrame.
    	 */
    	 
    	public void newFrame() {
    		
    		// Sets the windows title.
    		setTitle("TEST");
    		
    		// Sets the windows size.
    		setSize(width,height);
    		
    		// Sets the windows default closing operation.
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		// Sets the window default layout.
    	//	setBorderLayout(new BorderFactory())
    	
    		// Calls buildPanel Method.
    		buildPanel();
    		
    		
    		
    		// Sets the window visible.
    		setVisible(true);
    				// JLabel.
    		label1 = new JLabel("Please enter in your name");
    		
    		// JTextField.
    		JTF = new JTextField(10);
    		
    		// JButton.
    		button1 = new JButton("Enter");
    		button1.addActionListener(new Actions());
    		
    		// JPanel.
    		panel1 = new JPanel();
    		
    		// Adds components to JPanel.
    		panel1.add(label1);
    		panel1.add(JTF);
    		panel1.add(button1);
    		add(panel1);
    	}
    	
    	/**
    	 * Builds the components for the JFrame.
    	 */
    	 
    	public void buildPanel() {
    		
    
    	}
    	
    }
    I put everything into one method just to test, I know it's sloppy.
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jul 2008
    Posts
    109
    Thanks given
    0
    Thanks received
    0
    Rep Power
    36
    lolol, how do you except it to show when the parentComponent is set to null?

    set the parentComponent to the instance of Build:
    Code:
    if (actionCommand.equals("Enter"))
        JOptionPane.showMessageDialog(build, word);
    Stop looking at my signature, fag.
    Reply With Quote  
     

  3. #3  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    you have to declare JOptionPane as null.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Jul 2008
    Posts
    109
    Thanks given
    0
    Thanks received
    0
    Rep Power
    36
    Quote Originally Posted by Dennis View Post
    you have to declare JOptionPane as null.
    no you dont.
    you have to pass the parent component, which in this case is your 'build' frame..
    Stop looking at my signature, fag.
    Reply With Quote  
     

  5. #5  
    Member

    Join Date
    Dec 2007
    Posts
    1,094
    Thanks given
    8
    Thanks received
    8
    Rep Power
    0
    it still didn't work.
    Reply With Quote  
     

  6. #6  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    Quote Originally Posted by abraham2119 View Post
    lolol, how do you except it to show when the parentComponent is set to null?
    Just means that it's independent, it doesn't need a parent component.

    Code:
    package GUI;
    
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    
    public class Frame extends JFrame {
        JPanel panel1 = new JPanel();
        JButton button1 = new JButton();
        JLabel label1 = new JLabel();
        JTextField JTF = new JTextField();
    
        public static void main(String[] args) {
            new Frame().setVisible(true);
        }
        public Frame() {
    
            final int width = 250;
            final int height = 350;
    
            // Sets the windows title.
            setTitle("TEST");
    
            // Sets the windows size.
            setSize(width,height);
    
            // Sets the windows default closing operation.
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            // Sets the window default layout.
            //	setBorderLayout(new BorderFactory())
    
            // JLabel.
            label1 = new JLabel("Please enter in your name");
    
            // JTextField.
            JTF = new JTextField(10);
    
            // JButton.
            button1 = new JButton("Enter");
            button1.addActionListener(new ActionHandler());
    
            // JPanel.
            panel1 = new JPanel();
    
            // Adds components to JPanel.
            panel1.add(label1);
            panel1.add(JTF);
            panel1.add(button1);
            add(panel1);
        }
        class ActionHandler implements ActionListener {
    
            public void actionPerformed(ActionEvent e) {
    
                String actionCommand = e.getActionCommand();
    
                String word = JTF.getText();
                if (actionCommand.equals("Enter")) {
                    JOptionPane.showMessageDialog(null, word);
                }
            }
        }
    }
    Fixed.
    It's not tested but I know it will work.
    Reply With Quote  
     

  7. #7  
    Registered Member thiefmn6092's Avatar
    Join Date
    Dec 2006
    Age
    21
    Posts
    2
    Thanks given
    26
    Thanks received
    389
    Rep Power
    0
    dont you have to set it to be visible? i don't do any java ui programming so i am not sure.
    [Only registered and activated users can see links. ]

    If you are a starter and want to learn rsps coding, i think that the server that fits most of your requests is deathlypvpz.
    I know some stone heads will flame and say its shit, i completely agree buy deathlypvpz is the best thing to start with.
    And you must do some Java courses in codecademy to improve yourself.
    Reply With Quote  
     

  8. #8  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    Quote Originally Posted by thiefmn6092 View Post
    dont you have to set it to be visible? i don't do any java ui programming so i am not sure.
    it was being set visible, the creator is just a moron who doesnt know shit about anything
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •