Yeah, say if it was .println("ff"+deliveryName); it would show "ff"
Printable View
Yeah, say if it was .println("ff"+deliveryName); it would show "ff"
Does it print BEFORE the user enters anything in the text field?
Code JAVA:public void deliveryWindow(){ JFrame newFrame = new JFrame("Delivery Details"); Container pane = getContentPane(); newFrame.setLayout(new FlowLayout()); newFrame.setSize(new Dimension(250, 250)); //newFrame.getContentPane().add(panel); newFrame.setLocation(300,300); newFrame.setSize(250,250); newFrame.setVisible(true); JButton submitButton = new JButton("submit"); newFrame.add(submitButton); ButtonEventHandler handler = new ButtonEventHandler(); submitButton.addActionListener(handler); JPanel name = new JPanel(); JLabel nameLabel = new JLabel(); nameLabel.setText("Name :"); JTextField nameField = new JTextField(15); name.add(nameLabel); newFrame.add(nameLabel); newFrame.add(nameField); } private class ButtonEventHandler implements ActionListener { public void actionPerformed(ActionEvent e) { name1=nameField.getText(); if (e.getActionCommand().equals("submit")) { JOptionPane.showMessageDialog(null,"Your name is" + name1 ,"Message",JOptionPane.INFORMATION_MESSAGE); } else JOptionPane.showMessageDialog(null,"Nothing"); }}
Now Run this Code.. The Mistake you did is the place where u assigned the value of Text to the String deliveryName.. You should place it in the ActionPerformed Method..
@vigneshwaran
Which do you think is a good way to help a beginner learn to solve programming problemns?
Find his problem and give him the solution. AKA spoonfeeding
or
Help the OP find what is causing the problem and work with to help him find the solution
If the OP is given the solution and not taught how to debug his code, how will he become a better programmer?
@ Norm : What's the Mistake i did?
--- Update ---
I just corrected the mistake he did. Not Spoonfeeded.
Sorry, you gave him the answer without helping him debug the code and find what the problem was = spoon feeding.
Oh ok ok.. I'm new to here. I should let him solve. Anyway. Thanks 4 ur reply
What I try to do is to help the OP find the problem and solve it. That takes a few more steps and time.Quote:
I should let him solve