悟
悟峰
Unregistered / Unconfirmed
GUEST, unregistred user!
java問題,jc編輯,代碼如下:
package myprojects.midapplicationdemo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Midapplicationdemo extends JFrame implements ActionListener
{
JButton b=new JButton("建內部窗體");
JDesktopPane desk=new JDesktopPane();
int count=1;
public Midapplicationdemo() {
Container contentpane=getContentPane();
JPanel pnl=new JPanel();
pnl.add(b);
desk.setLayout(new FlowLayout());
b.addActionListener(this);
contentpane.add(pnl,BorderLayout.NORTH);
contentpane.add(pnl,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public static void main(String args[]) {
System.out.println("Starting Midapplicationdemo...");
Midapplicationdemo mainFrame = new Midapplicationdemo();
mainFrame.setSize(400, 400);
mainFrame.setTitle("Midapplicationdemo");
mainFrame.setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
JInternalFrame jif=new JInternalFrame(
"內部窗體["+count+++"]",true,true,true,true);
jif.setPreferredSize(new Dimension(250,100));
desk.add(jif);
desk.revalidate();
}
}
運行正常,但是不知道為什么MDI了窗體不顯示?
package myprojects.midapplicationdemo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Midapplicationdemo extends JFrame implements ActionListener
{
JButton b=new JButton("建內部窗體");
JDesktopPane desk=new JDesktopPane();
int count=1;
public Midapplicationdemo() {
Container contentpane=getContentPane();
JPanel pnl=new JPanel();
pnl.add(b);
desk.setLayout(new FlowLayout());
b.addActionListener(this);
contentpane.add(pnl,BorderLayout.NORTH);
contentpane.add(pnl,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
}
public static void main(String args[]) {
System.out.println("Starting Midapplicationdemo...");
Midapplicationdemo mainFrame = new Midapplicationdemo();
mainFrame.setSize(400, 400);
mainFrame.setTitle("Midapplicationdemo");
mainFrame.setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
JInternalFrame jif=new JInternalFrame(
"內部窗體["+count+++"]",true,true,true,true);
jif.setPreferredSize(new Dimension(250,100));
desk.add(jif);
desk.revalidate();
}
}
運行正常,但是不知道為什么MDI了窗體不顯示?