Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Swing / AWT / SWT
Plz help to add new window on current one!
Ishrat Hasan
Greenhorn
Posts: 2
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here's my code snippet -
public class ChatClient extends JFrame implements Serializable{ ChatClient() { super("Chat"); cc=this; JMenuBar bar = new JMenuBar(); setJMenuBar(bar); cntr = getContentPane(); cntr.setLayout( new FlowLayout()); desktop = new JDesktopPane(); cntr.add( desktop ); rs = new ReadServer(this); JMenu loginMenu = new JMenu( "Login"); loginMenu.setMnemonic( 'L'); JMenuItem loginItem = new JMenuItem( "Login..."); loginItem.setMnemonic( 'o' ); loginItem.addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent e){ login(); } } ); loginMenu.add(loginItem); setSize(300,400); show(); } //Method for new login window void login(){ JInternalFrame intframe = new JInternalFrame("Login",true,true,true,true); Container lcntr = intframe.getContentPane(); lcntr.setLayout( new FlowLayout() ); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout(FlowLayout.CENTER, 34, 44)); logID = new JLabel("LoginID"); panel.add(logID); login = new JTextField(23); panel.add(login); lpswd = new JLabel("Password"); panel.add(lpswd); pswd = new JPasswordField(20); panel.add(pswd); ok = new JButton(" OK "); cancel = new JButton("Cancel"); panel.add(ok); panel.add(cancel); ok.addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent e){ String log = login.getText(); String pwd = pswd.getText(); if ( !(log.equals("") || pwd.equals("")) ) { String message = "#L"+log + "+" + pwd; try{ System.out.println("writing: "+message); out.writeObject(message); }catch(IOException ioe){ ioe.printStackTrace();} } else { JOptionPane.showMessageDialog( null, "Please fill both Login and Password."); } } } ); cancel.addActionListener( new ActionListener(){ public void actionPerformed( ActionEvent e ){ String message = "close"; try{ System.out.println("writing: "+message); out.writeObject(message); }catch(IOException ioe){ ioe.printStackTrace();} System.exit(0); } } ); lcntr.add(panel); intframe.setOpaque(true); desktop.add( intframe ); setSize(325,150); show(); } public static void main(String args[]){ final ChatClient2 app = new ChatClient2(); app.addWindowListener( new WindowAdapter(){ public void windowClosing( WindowEvent e){ System.exit(0); } } ); } }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
jmenubar,menuitem
Exception Null
internal frame error
internal frame error
Adding a new JMenu to an existing JMenuBar
More...