Results 1 to 2 of 2
Thread: Problem with JInternalFrame
- 12-11-2008, 02:07 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 1
- Rep Power
- 0
Problem with JInternalFrame
im suppose to show an Internal Frame when the button is pressed...but nothing is showing except the dialogue box i've put. Here's the code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Search extends JFrame {
JLabel label1;
JTextField text1;
JButton button1;
JPanel buttonPanel;
JDesktopPane desktop = new JDesktopPane();
public Search(){
super("Search On Employee");
Container container=getContentPane();
container.add(desktop);
container.setLayout(null);
//buttonPanel = new JPanel();
//buttonPanel.setLayout( new GridLayout( 5,7 ) );
label1=new JLabel("Employee ID: ");
container.add(label1);
text1=new JTextField(15);
container.add(text1);
button1=new JButton("Search");
//buttonPanel.add( button1 );
//container.add( buttonPanel, BorderLayout.SOUTH );
container.add(button1);
Insets insets = container.getInsets();
Dimension size = label1.getPreferredSize();
label1.setBounds(10 + insets.left, 20 + insets.top, size.width, size.height);
size = text1.getPreferredSize();
text1.setBounds(100 + insets.left, 19 + insets.top, size.width, size.height);
size = button1.getPreferredSize();
button1.setBounds(177 + insets.left, 90 + insets.top, size.width+15 , size.height+15);
setSize( 340,250);
setVisible( true );
ButtonHandelar handler = new ButtonHandelar();
button1.addActionListener( handler );}//Search
public void showInternal(){
JInternalFrame frame=new JInternalFrame("Internal",true,true,true,true);
frame.setSize(320,240);
desktop.add(frame);
frame.setVisible(true);
System.out.println("in the internal...");
}
public static void main(String a[]){
Search application = new Search();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); }//main
private class ButtonHandelar implements ActionListener {
// process Button events
public void actionPerformed( ActionEvent event )
{
String string = "";
if ( event.getSource() == button1 )
{
string = "EMPID: " + text1.getText() ;
JOptionPane.showMessageDialog( null, string );
showInternal();
}
else
System.exit(0);
}//button handler
}//jframe
}
-
I recommend that you avoid using the "null" layout like the plague and that you read up on how to use layout managers.
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Fubar extends JFrame { JLabel label1; JTextField text1; JButton button1; JPanel buttonPanel; JDesktopPane desktop = new JDesktopPane(); public Fubar() { super("Search On Employee"); Container container = getContentPane(); container.add(new JScrollPane(desktop)); JPanel topPanel = new JPanel(); label1 = new JLabel("Employee ID: "); topPanel.add(label1); text1 = new JTextField(15); topPanel.add(text1); button1 = new JButton("Search"); topPanel.add(button1); container.add(topPanel, BorderLayout.NORTH); container.setPreferredSize(new Dimension(340, 250)); setVisible(true); ButtonHandelar handler = new ButtonHandelar(); button1.addActionListener(handler); }// Search public void showInternal() { JInternalFrame frame = new JInternalFrame("Internal", true, true, true, true); frame.setBounds(0, 0, 320, 240); desktop.add(frame); frame.setVisible(true); System.out.println("in the internal..."); } public static void main(String a[]) { Fubar application = new Fubar(); application.pack(); application.setLocationRelativeTo(null); application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); application.setVisible(true); }// main private class ButtonHandelar implements ActionListener { // process Button events public void actionPerformed(ActionEvent event) { String string = ""; if (event.getSource() == button1) { string = "EMPID: " + text1.getText(); JOptionPane.showMessageDialog(null, string); showInternal(); } else System.exit(0); }//button handler }//jframe }
Similar Threads
-
[SOLVED] jScrool in JInternalFrame
By gustio in forum New To JavaReplies: 2Last Post: 07-22-2008, 10:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks