Results 1 to 7 of 7
Thread: TextField not displayed
- 04-16-2011, 11:07 PM #1
Member
- Join Date
- Apr 2011
- Location
- SoCal
- Posts
- 10
- Rep Power
- 0
TextField not displayed
How come TextField "name" is not displayed when button "mem" is clicked?
Java Code:import java.applet.*; import java.awt.*; import javax.swing.JButton; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Test extends Applet implements ActionListener { Font Title = new Font("Arial",Font.BOLD,40); Font Normal = new Font("Arial",Font.PLAIN,20); JButton mem, nonmem; TextField name; public void init() { setLayout(null); Color background = new Color(179,50,55); setBackground(background); mem = new JButton("I am an existing member"); mem.addActionListener(this); nonmem = new JButton("I am new"); nonmem.addActionListener(this); mem.setBounds(20,100,200,30); nonmem.setBounds(20,150,200,30); name = new TextField("Please Enter Your Name Here"); name.setBounds(20,100,300,25); name.addActionListener(this); } public void actionPerformed(ActionEvent e) { String source = e.getActionCommand(); mem.setVisible(false); nonmem.setVisible(false); if (source.equals(mem)) { add(name); } else if (source.equals(nonmem)) { } else if (source.equals(name)) { } } public void stop() { } public void paint (Graphics g) { super.paint(g); g.setFont(Title); g.drawString("Welcome to Movie2Go Kiosk Services",250,50); g.setFont(Normal); add(mem); add(nonmem); } }
- 04-17-2011, 01:11 AM #2
Why are you comparing a String with JButton's and JTextField's in the actionPerformed method?
- 04-17-2011, 01:30 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
1. You need to decide whether you are creating an AWT or Swing applet. I would suggest you spend your time learning Swing since that is what most developers use these days. This means don't mix component JButton is Swing. Applet, TextField are AWT. Swing components have a "J" at the beginning.
2. There is no good reason to override the paint() method of the top level container like a JApplet, JFrame or JDialog. If fact I don't see any reason for doing the custom painting. You add the button and the text field to the applet, so why don't you just add a JLabel as well?
3. Adding a component will not show the component. You need to tell Swing that a component has been added to the panel by using panel.revalidate().
- 04-17-2011, 03:47 AM #4
- 04-17-2011, 03:59 AM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
revalidate() is for Swing. validate() is for AWT.
- 04-17-2011, 04:20 AM #6
- 04-18-2011, 02:37 AM #7
Member
- Join Date
- Apr 2011
- Location
- SoCal
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
output is not displayed
By meth in forum New To JavaReplies: 0Last Post: 01-07-2011, 05:44 AM -
ImageIcon : Image not displayed
By niteshwar.bhardwaj in forum Java 2DReplies: 0Last Post: 02-13-2009, 07:36 AM -
Nodes displayed in JTree
By Orange in forum AWT / SwingReplies: 6Last Post: 08-08-2008, 05:07 AM -
Tooltip not getting displayed...
By Preethi in forum New To JavaReplies: 4Last Post: 07-31-2008, 10:00 AM -
displayed the rownumbers
By geeta_ravikanti in forum JDBCReplies: 1Last Post: 04-22-2008, 02:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks