A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
JDialog : Custom Input
Darren Wilkinson
Greenhorn
Joined: Feb 09, 2004
Posts: 21
posted
Sep 15, 2004 15:26:00
0
Hello :-)
I need to make a modal dialog window that requires the user to input text into 3 textfields
It also needs two buttons
A cancel button (which gets rid of the dialog)
Another button which passes the users text on to the class that created the dialog
Can anyone point me in the right direction on this please
Darren
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Sep 15, 2004 16:54:00
0
This might get you started (it's rough)
import java.awt.*; import java.awt.event.*; import javax.swing.*; class Testing extends JFrame { JLabel lbl = new JLabel("Name = "); public Testing() { setDefaultCloseOperation(EXIT_ON_CLOSE); setLocation(400,300); JPanel main = new JPanel(new BorderLayout()); main.add(lbl,BorderLayout.NORTH); JButton btn = new JButton("Enter name"); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { class GetName extends JDialog { JTextField tf = new JTextField(10); public GetName() { setModal(true); setLocation(400,300); getContentPane().setLayout(new BorderLayout()); getContentPane().add(tf,BorderLayout.NORTH); JButton btn1 = new JButton("Add Name"); btn1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ lbl.setText("Name = "+tf.getText()); dispose();}}); getContentPane().add(btn1); pack(); setVisible(true); } } new GetName();}}); main.add(btn,BorderLayout.SOUTH); getContentPane().add(main); pack(); } public static void main(String[] args){new Testing().setVisible(true);} }
Darren Wilkinson
Greenhorn
Joined: Feb 09, 2004
Posts: 21
posted
Sep 16, 2004 03:27:00
0
Thank you
This has pointed me in the right direction
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
I like...
posted
Sep 16, 2004 08:22:00
0
Originally posted by Darren Wilkinson:
Thank you
This has pointed me in the right direction
It did a little more than point. I hope this wasn't a homework assignment..Michael, are you listening?
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: JDialog : Custom Input
Similar Threads
Flexible Dialog Box
JAVA Command Line jar file - Debug in Eclipse
browse button
changing txt value of a button in SWT
A question about GUI
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter