to DanielYWoo(小丹尼):
index.java:316: setSelected(boolean) in javax.swing.JInternalFrame cannot be applied to ()
index.java:316: setSelected(boolean) in javax.swing.JInternalFrame cannot be applied to ()
调试欢乐多
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class QQQ extends JFrame
{
JDesktopPane desk = new JDesktopPane();
JInternalFrame if1 = new JInternalFrame();
JInternalFrame if2 = new JInternalFrame();
JButton bt1 = new JButton("Switch 1");
JButton bt2 = new JButton("Switch 2"); QQQ()
{
JPanel temp = new JPanel();
temp.add(bt1);
temp.add(bt2);
getContentPane().add(temp, BorderLayout.NORTH);
getContentPane().add(desk, BorderLayout.CENTER);
desk.add(if1);
desk.add(if2);
if1.reshape(10,10,100,100);
if2.reshape(30,30,100,100);
if1.setVisible(true);
if2.setVisible(true);
bt1.addActionListener(new MyListener());
bt2.addActionListener(new MyListener());
setBounds(100,100,400,400);
show();
}
public static void main(String[] args)
{
QQQ q = new QQQ();
}
class MyListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
if(e.getSource()==bt1)
if1.setSelected(true);
else
if2.setSelected(true);
}
catch (Exception ex)
{
} }
};
}
import java.awt.*;
import java.awt.event.*;public class index extends JFrame
{
JDesktopPane desktop = new JDesktopPane();
JInternalFrame jf1;
int i=5;
int j=5;
index(String title)
{
super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("文件");
JMenuItem openfile = new JMenuItem("open");
openfile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
openfile_actionPerformed(e);
}
});
file.add(openfile);
mb.add(file);
setJMenuBar(mb);
getContentPane().add(desktop);
setSize(600,400);
setVisible(true);
} public void openfile_actionPerformed(ActionEvent e)
{
jf1 = new JInternalFrame("aa",true,true,true,true);
jf1.setSize(100,75);
jf1.setLocation(i,j);
i+=20;j+=20;
if(i>120){i=5;j=5;}
jf1.setVisible(true);
desktop.add(jf1);
}
public static void main(String[] args)
{
new index("aa");
}
}
import java.awt.*;
import java.awt.event.*;public class index extends JFrame
{
JDesktopPane desktop = new JDesktopPane();
JInternalFrame jf1;
int i=5;
int j=5;
index(String title)
{
super(title);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem openfile = new JMenuItem("open");
openfile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
openfile_actionPerformed(e);
}
});
file.add(openfile);
mb.add(file);
setJMenuBar(mb);
getContentPane().add(desktop);
setSize(600,400);
setVisible(true);
} public void openfile_actionPerformed(ActionEvent e)
{
jf1 = new JInternalFrame("aa",true,true,true,true);
jf1.setSize(100,75);
jf1.setLocation(i,j);
i+=20;j+=20;
if(i>120){i=5;j=5;}
jf1.setVisible(true);
desktop.add(jf1);
try{
jf1.setSelected(true);
}catch(Exception ex){
System.out.println(ex);
}
}
public static void main(String[] args)
{
new index("aa");
}
}