我正在处理一个项目。在面板类中,我已经定义了一个mouselistener来调用桌面窗格中的第二个iframe,但它没有显示出来?
请帮助 感谢
主要类
public class Try2 extends JFrame{
JTabbedPane pane;
public Try2() {
setSize(800,500);
setDefaultCloseOperation(Try2.EXIT_ON_CLOSE);
setVisible(true);
pane=new JTabbedPane();
pane.addTab("First", new desktoppane());
pane.addTab("Second", new JPanel());
setContentPane(pane);
}
public static void main(String[] args) {
new Try2();
}
DesktopPane类
public class desktoppane extends JDesktopPane{
public desktoppane() {
// setOpaque(false);
JButton btnfirst=new JButton("First IFrame");
btnfirst.setSize(150,25);
add(btnfirst);
btnfirst.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
first f=new first();
add(f);
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
}
}
第一个IFrame
public class first extends JInternalFrame{
public first() {
setSize(400, 400);
setVisible(true);
setClosable(true);
add(new paneel());
}
}
小组类
public class paneel extends JPanel{
public paneel() {
setBackground(Color.red);
setSize(200,200);
JButton btnSecond=new JButton("Second IFrame");
btnSecond.setSize(150,25);
add(btnSecond);
btnSecond.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
Second s=new Second();
desktoppane p=new desktoppane();
p.add(s);
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
}
}
第二个IFrame
public class Second extends JInternalFrame{
public Second() {
setSize(400, 400);
setVisible(true);
setClosable(true);
setBackground(Color.yellow);
}
}
答案 0 :(得分:2)
您正在面板类中创建一个新的桌面窗格,但您不会将其添加到任何内容中。它应该可以添加到您的JFrame中。或者您可能希望将IFrame添加到现有桌面窗格中,而不是新窗格。