问题1:现在在主窗口的一个函数的中间部分。new了一个对话框。对话框里有一个jtextfield和ok按钮。在jtextfiled里面输入内容。点击ok。然后返回主窗口的函数。根据jtextfield里的值函数继续执行。但当我在里面输入值。点击ok程序不执行了。。
程序如下:
public void drop(DropTargetDropEvent dtde) {
。
。
AddNodeMessage addNodeMessage = new AddNodeMessage();
addNodeMessage.setSize(300, 150);
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = addNodeMessage.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
addNodeMessage.setLocation( (screenSize.width - frameSize.width) /
2,
(screenSize.height - frameSize.height) /
2);
addNodeMessage.setVisible(true);。
。
}
AddNodeMessage 类如下
package TestApp;import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class AddNodeMessage
extends JDialog {
JPanel panel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JToggleButton jToggleButton1 = new JToggleButton();
JToggleButton jToggleButton2 = new JToggleButton();
public boolean dragPermitFlag = false; public AddNodeMessage(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch (Exception ex) {
ex.printStackTrace();
}
} public AddNodeMessage() {
this(null, "", false);
} private void jbInit() throws Exception {
panel1.setLayout(xYLayout1);
jLabel1.setText("名字");
jTextField1.setText("");
jLabel2.setText("请输入名字");
jToggleButton1.setText("cancel");
jToggleButton2.setText("OK");
jToggleButton2.addActionListener(new AddNodeMessage_jToggleButton2_actionAdapter(this));
getContentPane().add(panel1);
panel1.add(jToggleButton1, new XYConstraints(178, 72, 93, 26));
panel1.add(jToggleButton2, new XYConstraints(280, 72, 95, 26));
panel1.add(jLabel1, new XYConstraints(24, 18, 51, 25));
panel1.add(jTextField1, new XYConstraints(77, 17, 280, 25));
panel1.add(jLabel2, new XYConstraints(78, 50, 280, 22));
} void jToggleButton2_actionPerformed(ActionEvent e) {
dragPermitFlag = true;
this.setVisible(false);
return;
}
}class AddNodeMessage_jToggleButton2_actionAdapter implements java.awt.event.ActionListener {
AddNodeMessage adaptee; AddNodeMessage_jToggleButton2_actionAdapter(AddNodeMessage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton2_actionPerformed(e);
}
}2....我现在的主窗口是jdialog,子窗口也是jdialog。我怎么实现让子窗口不关闭主窗口不能得到焦点
程序如下:
public void drop(DropTargetDropEvent dtde) {
。
。
AddNodeMessage addNodeMessage = new AddNodeMessage();
addNodeMessage.setSize(300, 150);
Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
Dimension frameSize = addNodeMessage.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
addNodeMessage.setLocation( (screenSize.width - frameSize.width) /
2,
(screenSize.height - frameSize.height) /
2);
addNodeMessage.setVisible(true);。
。
}
AddNodeMessage 类如下
package TestApp;import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class AddNodeMessage
extends JDialog {
JPanel panel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JToggleButton jToggleButton1 = new JToggleButton();
JToggleButton jToggleButton2 = new JToggleButton();
public boolean dragPermitFlag = false; public AddNodeMessage(Frame frame, String title, boolean modal) {
super(frame, title, modal);
try {
jbInit();
pack();
}
catch (Exception ex) {
ex.printStackTrace();
}
} public AddNodeMessage() {
this(null, "", false);
} private void jbInit() throws Exception {
panel1.setLayout(xYLayout1);
jLabel1.setText("名字");
jTextField1.setText("");
jLabel2.setText("请输入名字");
jToggleButton1.setText("cancel");
jToggleButton2.setText("OK");
jToggleButton2.addActionListener(new AddNodeMessage_jToggleButton2_actionAdapter(this));
getContentPane().add(panel1);
panel1.add(jToggleButton1, new XYConstraints(178, 72, 93, 26));
panel1.add(jToggleButton2, new XYConstraints(280, 72, 95, 26));
panel1.add(jLabel1, new XYConstraints(24, 18, 51, 25));
panel1.add(jTextField1, new XYConstraints(77, 17, 280, 25));
panel1.add(jLabel2, new XYConstraints(78, 50, 280, 22));
} void jToggleButton2_actionPerformed(ActionEvent e) {
dragPermitFlag = true;
this.setVisible(false);
return;
}
}class AddNodeMessage_jToggleButton2_actionAdapter implements java.awt.event.ActionListener {
AddNodeMessage adaptee; AddNodeMessage_jToggleButton2_actionAdapter(AddNodeMessage adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jToggleButton2_actionPerformed(e);
}
}2....我现在的主窗口是jdialog,子窗口也是jdialog。我怎么实现让子窗口不关闭主窗口不能得到焦点
void jToggleButton2_actionPerformed(ActionEvent e) {
dragPermitFlag = true;
this.getOwner.show();//大概是这样,反正再这里要得到父窗口。
this.setVisible(false);
return;
}
可以试试使用模态窗口