当前位置: 技术问答>java相关
一个JDesktop的问题
来源: 互联网 发布时间:2015-11-05
本文导语: 为什么下面代码只显示JDesktop desktop而JInternalFrame fr1却不能显示出来? import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class CommonLayouts extends JF...
为什么下面代码只显示JDesktop desktop而JInternalFrame fr1却不能显示出来?
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class CommonLayouts extends JFrame{
public CommonLayouts() {
super("Common Layout Managers");
setSize(500,380);
JDesktopPane desktop = new JDesktopPane();
getContentPane().add(desktop);
JInternalFrame fr1 = new JInternalFrame("FlowLayout", true, true);
fr1.setBounds(10, 10, 150, 150);
Container c = fr1.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JButton("1"));
c.add(new JButton("2"));
c.add(new JButton("3"));
c.add(new JButton("4"));
desktop.add(fr1, 0);
try {
fr1.setSelected(true);
}
catch (java.beans.PropertyVetoException ex) {}
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
}
public static void main(String args[]) {
new CommonLayouts();
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class CommonLayouts extends JFrame{
public CommonLayouts() {
super("Common Layout Managers");
setSize(500,380);
JDesktopPane desktop = new JDesktopPane();
getContentPane().add(desktop);
JInternalFrame fr1 = new JInternalFrame("FlowLayout", true, true);
fr1.setBounds(10, 10, 150, 150);
Container c = fr1.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JButton("1"));
c.add(new JButton("2"));
c.add(new JButton("3"));
c.add(new JButton("4"));
desktop.add(fr1, 0);
try {
fr1.setSelected(true);
}
catch (java.beans.PropertyVetoException ex) {}
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
}
public static void main(String args[]) {
new CommonLayouts();
}
}
|
楼主,鉴于你的不小心,现惩罚你从下面的代码里边自己找出你的错误:)
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class CommonLayouts extends JFrame{
public CommonLayouts() {
super("Common Layout Managers");
setSize(500,380);
JDesktopPane desktop = new JDesktopPane();
getContentPane().add(desktop);
JInternalFrame fr1 = new JInternalFrame("FlowLayout", true, true);
fr1.setBounds(10, 10, 150, 150);
Container c = fr1.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JButton("1"));
c.add(new JButton("2"));
c.add(new JButton("3"));
c.add(new JButton("4"));
desktop.add(fr1, 0);
fr1.setVisible(true);
try {
fr1.setSelected(true);
}
catch (java.beans.PropertyVetoException ex) {}
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
}
public static void main(String args[]) {
new CommonLayouts();
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class CommonLayouts extends JFrame{
public CommonLayouts() {
super("Common Layout Managers");
setSize(500,380);
JDesktopPane desktop = new JDesktopPane();
getContentPane().add(desktop);
JInternalFrame fr1 = new JInternalFrame("FlowLayout", true, true);
fr1.setBounds(10, 10, 150, 150);
Container c = fr1.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JButton("1"));
c.add(new JButton("2"));
c.add(new JButton("3"));
c.add(new JButton("4"));
desktop.add(fr1, 0);
fr1.setVisible(true);
try {
fr1.setSelected(true);
}
catch (java.beans.PropertyVetoException ex) {}
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
}
public static void main(String args[]) {
new CommonLayouts();
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。