![]() |
#2
我不信2016-09-12 20:26
|

package swing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFrameTest {
public static void main(String[] args) {
JFrame myframe = new JFrame("my FRAME");
myframe.getContentPane().setLayout(new FlowLayout());
myframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myframe.addMouseListener(new FrameMouseAdapter(myframe));
myframe.setSize(400, 300);
myframe.setLocationRelativeTo(null);
JLabel jLabel = new JLabel();
jLabel.setText("请单击本窗口");
myframe.getContentPane().add(jLabel);
myframe.setVisible(true);
}
}
class FrameMouseAdapter extends MouseAdapter {
JFrame owner;
FrameMouseAdapter(JFrame owner) {
this.owner = owner;
}
public void mouseCliked(MouseEvent e) {
JDialog jDialog = new JDialog(owner, true);
jDialog.setTitle("这是一个对话框");
jDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jDialog.setBounds(400, 300, 282, 247);
jDialog.setResizable(false);
jDialog.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFrameTest {
public static void main(String[] args) {
JFrame myframe = new JFrame("my FRAME");
myframe.getContentPane().setLayout(new FlowLayout());
myframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myframe.addMouseListener(new FrameMouseAdapter(myframe));
myframe.setSize(400, 300);
myframe.setLocationRelativeTo(null);
JLabel jLabel = new JLabel();
jLabel.setText("请单击本窗口");
myframe.getContentPane().add(jLabel);
myframe.setVisible(true);
}
}
class FrameMouseAdapter extends MouseAdapter {
JFrame owner;
FrameMouseAdapter(JFrame owner) {
this.owner = owner;
}
public void mouseCliked(MouseEvent e) {
JDialog jDialog = new JDialog(owner, true);
jDialog.setTitle("这是一个对话框");
jDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jDialog.setBounds(400, 300, 282, 247);
jDialog.setResizable(false);
jDialog.setVisible(true);
}
}
只有本站会员才能查看附件,请 登录
应该还有一个窗口的呀