关于JAVA面板类的一个简单问题,求大神们帮忙
我的是浏览器界面,比如在当前浏览器的主界面面板中,我单机主面板中的一个按钮,然后弹出来一个新的对话面板,相当于一个对话窗口,请问,我如何写代码,才能让鼠标只能在当前弹出面...
我的是浏览器界面,比如在当前浏览器的主界面面板中,我单机主面板中的一个按钮,然后弹出来一个新的对话面板,相当于一个对话窗口,请问,我如何写代码,才能让鼠标只能在当前弹出面板中操作,当前面板之外的一律无法点击操作。求给出代码例子
我要的是java代码 展开
我要的是java代码 展开
3个回答
展开全部
你要的是java代码还是javascript代码?
java代码:
package com.ldc.delete;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class PanelClass extends JFrame {
private JPanel contentPanel;
private JButton showBtn;
private JButton testBtn;
private MyPopWin myPopWin;
public static void main(String[] args) {
new PanelClass();
}
public PanelClass() {
showMe();
}
private void showMe() {
this.setTitle("Panel Class");
this.setSize(400, 300);
this.setLocation(50, 50);
contentPanel = new JPanel();
this.setContentPane(contentPanel);
showBtn = new JButton("Show");
showBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(null == myPopWin) {
myPopWin = new MyPopWin(PanelClass.this, true);
}
myPopWin.show();
}
});
contentPanel.add(showBtn);
testBtn = new JButton("Test");
testBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(PanelClass.this, "test");
}
});
contentPanel.add(testBtn);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private class MyPopWin extends JDialog {
private JButton okBtn;
private Frame parentFrame;
/**
*
* @param owner 父窗体
* @param modal 为true时则不能在dialog显示时操作父窗体
*/
public MyPopWin(Frame owner, boolean modal) {
super(owner, modal);
this.parentFrame = owner;
initDialog();
}
private void initDialog() {
this.setSize(200, 150);
this.setTitle(parentFrame.getTitle());
//父窗体的位置
Point pl = parentFrame.getLocation();
//父窗体的大小
Dimension ps = parentFrame.getSize();
//将窗体定位到父窗体的中央
int x = pl.x + (ps.width - this.getWidth()) / 2;
int y = pl.y + (ps.height - this.getHeight()) / 2;
this.setLocation(x, y);
this.setLayout(null);
okBtn = new JButton("OK");
okBtn.setBounds(50, 50, 78, 25);
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MyPopWin.this.setVisible(false);
}
});
this.add(okBtn);
}
}
}
java代码:
package com.ldc.delete;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class PanelClass extends JFrame {
private JPanel contentPanel;
private JButton showBtn;
private JButton testBtn;
private MyPopWin myPopWin;
public static void main(String[] args) {
new PanelClass();
}
public PanelClass() {
showMe();
}
private void showMe() {
this.setTitle("Panel Class");
this.setSize(400, 300);
this.setLocation(50, 50);
contentPanel = new JPanel();
this.setContentPane(contentPanel);
showBtn = new JButton("Show");
showBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(null == myPopWin) {
myPopWin = new MyPopWin(PanelClass.this, true);
}
myPopWin.show();
}
});
contentPanel.add(showBtn);
testBtn = new JButton("Test");
testBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(PanelClass.this, "test");
}
});
contentPanel.add(testBtn);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private class MyPopWin extends JDialog {
private JButton okBtn;
private Frame parentFrame;
/**
*
* @param owner 父窗体
* @param modal 为true时则不能在dialog显示时操作父窗体
*/
public MyPopWin(Frame owner, boolean modal) {
super(owner, modal);
this.parentFrame = owner;
initDialog();
}
private void initDialog() {
this.setSize(200, 150);
this.setTitle(parentFrame.getTitle());
//父窗体的位置
Point pl = parentFrame.getLocation();
//父窗体的大小
Dimension ps = parentFrame.getSize();
//将窗体定位到父窗体的中央
int x = pl.x + (ps.width - this.getWidth()) / 2;
int y = pl.y + (ps.height - this.getHeight()) / 2;
this.setLocation(x, y);
this.setLayout(null);
okBtn = new JButton("OK");
okBtn.setBounds(50, 50, 78, 25);
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MyPopWin.this.setVisible(false);
}
});
this.add(okBtn);
}
}
}
展开全部
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class JFrameTest extends JFrame implements ActionListener{
JButton jbtn=null;
public JFrameTest(){
this.setLayout(new FlowLayout());
jbtn = new JButton("点击");
jbtn.addActionListener(this);
this.add(jbtn);
this.setResizable(false);
this.setBounds(100,100,400, 300);
this.setVisible(true);
}
public static void main(String args[]){
new JFrameTest();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jbtn){
new JDialogTest(this,"管理系统",true);
}
}
class JDialogTest extends JDialog{
JDialogTest(JFrame owner, String title, boolean modal){
//这句必加要不没效果
super(owner,title,modal);
this.setTitle(title);
this.setSize(200, 100);
this.setVisible(true);
}
}
}
//你开一看看韩顺平的学生管理系统,哪个更详细
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class JFrameTest extends JFrame implements ActionListener{
JButton jbtn=null;
public JFrameTest(){
this.setLayout(new FlowLayout());
jbtn = new JButton("点击");
jbtn.addActionListener(this);
this.add(jbtn);
this.setResizable(false);
this.setBounds(100,100,400, 300);
this.setVisible(true);
}
public static void main(String args[]){
new JFrameTest();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jbtn){
new JDialogTest(this,"管理系统",true);
}
}
class JDialogTest extends JDialog{
JDialogTest(JFrame owner, String title, boolean modal){
//这句必加要不没效果
super(owner,title,modal);
this.setTitle(title);
this.setSize(200, 100);
this.setVisible(true);
}
}
}
//你开一看看韩顺平的学生管理系统,哪个更详细
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你写鼠标移动事件,当移动到面板中才出发事件。在事件中弹出对话面板
追问
什么叫移动到面板中才发出事件?
这个面板是主面板么?
我是在主面板中 点按钮弹出窗口。。。
追答
onmouseover不知道吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询