java JDialog问题 5
这是一个窗体。classShitiSearchextendsJFrame{privateJPanelcontentPane;privateJTextFieldtihao;...
这是一个窗体。
class ShitiSearch extends JFrame
{
private JPanel contentPane;
private JTextField tihao;
private JTextField tineirong;
//ShitiSearch frame = new ShitiSearch();
public ShitiSearch()
{
.............................
.............................
JButton button = new JButton("删除试题"); //定义了一个按钮
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteT del = new deleteT();
}
});
}
//下面是一个对话框
class deleteT extends JDialog implements ActionListener
{
public deleteT() /
{
..............
}
}
我的问题是:如何指定对话框的父类窗口为ShitiSearch,而且让其弹出时,父类不能动。谢谢! 展开
class ShitiSearch extends JFrame
{
private JPanel contentPane;
private JTextField tihao;
private JTextField tineirong;
//ShitiSearch frame = new ShitiSearch();
public ShitiSearch()
{
.............................
.............................
JButton button = new JButton("删除试题"); //定义了一个按钮
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
deleteT del = new deleteT();
}
});
}
//下面是一个对话框
class deleteT extends JDialog implements ActionListener
{
public deleteT() /
{
..............
}
}
我的问题是:如何指定对话框的父类窗口为ShitiSearch,而且让其弹出时,父类不能动。谢谢! 展开
1个回答
展开全部
JDialog dialog = new JDialog(shitiSearch, true); // 第二个参数设置型念为true就可以卜大困了
例:
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.JPanel;
@SuppressWarnings("serial")
public class TestMain extends JFrame {
public TestMain() {
super("仿基测试窗口");
JPanel pane = new JPanel();
JButton button = new JButton("JDialog");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openJDialog();
}
});
getContentPane().add(pane);
pane.add(button);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
setLocationRelativeTo(null);
setVisible(true);
}
private void openJDialog(){
JDialog dialog = new JDialog(this, true);
dialog.setSize(200, 100);
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
}
public static void main(String[] args) {
new TestMain();
}
}
例:
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.JPanel;
@SuppressWarnings("serial")
public class TestMain extends JFrame {
public TestMain() {
super("仿基测试窗口");
JPanel pane = new JPanel();
JButton button = new JButton("JDialog");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openJDialog();
}
});
getContentPane().add(pane);
pane.add(button);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 200);
setLocationRelativeTo(null);
setVisible(true);
}
private void openJDialog(){
JDialog dialog = new JDialog(this, true);
dialog.setSize(200, 100);
dialog.setLocationRelativeTo(this);
dialog.setVisible(true);
}
public static void main(String[] args) {
new TestMain();
}
}
追问
不行啊,JDialog dialog = new JDialog(shitiSearch, true); hitiSearch是一个类名,不是该类的一个对象啊。
JDialog(JFrame owner,Boolean modal)中的owner是一个JFrame对象
追答
shitiSearch 你要改一下,我这里所指的就是父层窗口对象,如果你是继承的JFrame,就可以用this关键字
我后面写的那个例子用的就是this关键字
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询