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

Here is my code:
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.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); } } }
Here is my build class:
I put everything into one method just to test, I know it's sloppy.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() { } }
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);

you have to declare JOptionPane as null.

it still didn't work.

Just means that it's independent, it doesn't need a parent component.
Fixed.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); } } } }
It's not tested but I know it will work.
dont you have to set it to be visible? i don't do any java ui programming so i am not sure.

| « what the crap | The Difference Between Java & JavaScript » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |