这个问题很严重,值50分,进来,马上给分! JOptionPane.showMessageDialog(this,"测试","警告"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void actionPerformed(ActionEvent e){ new JOptionPane().showMessageDialog(this,"测试","警告"); System.exit(0); } 下面的代码是没有问题的.import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Untitled2 extends JFrame implements ActionListener { private JButton jButton1 = new JButton(); public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(this,"测试","警告",JOptionPane.ERROR_MESSAGE); return; } public Untitled2() throws HeadlessException { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) throws HeadlessException { Untitled2 untitled21 = new Untitled2(); untitled21.setSize(300,300); untitled21.show(); } private void jbInit() throws Exception { jButton1.setText("OK"); jButton1.addActionListener(this); this.getContentPane().add(jButton1, BorderLayout.CENTER); }} to:xmagicwu(死过方生) 不行呀,那岂不整个程序都退出了吗? to:: helpall() ( 在JFrame中用是没问题,但是你在JDialog中用用看 改动如下:class A extends JFrame{ public static void main(String[] args){ JDialog B=new JmyDialog(this); B.show(); }}class JmyDialog extends JDialog implenents ActionListener{ JButton jButton; Frame parent; public B(Frame _parent){ super(_parent);// 一些布局初始化 jButton=new JButton("弹出消息"); jButton.addActionListener(this); } public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(parent,"测试","警告");//这里的this应该是Frame才对 return;} import javax.swing.JFrame;import javax.swing.JDialog;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JOptionPane;import java.awt.event.ActionEvent;public class A extends JFrame{ public static void main(String[] args){ JDialog b=new B(); b.show(); }}class B extends JDialog implements ActionListener{ JButton jButton; public B(){// 一些布局初始化 this.setBounds(100,100,200,200); jButton=new JButton("弹出消息"); jButton.addActionListener(this); this.getContentPane().add(jButton); } public void actionPerformed(ActionEvent e){ JOptionPane.showMessageDialog(this,"测试"); }}我试了,没问题的 在JFrame中用是没问题,但是你在JDialog中用用看===>很幸运,还是没有问题. geyf(我在学java) :你的方法我也尝试过,不行的 你那是不是有多个线程啊,如果是,需要用SwingUtilities.invokeLater()之类的方式来显示你的对话框 to geyf(我在学java) 不是多线程,就是简单的一个Frame显示一个Dialog,然后Dialog用JOptionPane.showMessage...显示一个消息对话框,但是按消息对话框的那个确定按钮之后,消息框不消息,但是后面的语句都执行了,怀疑和UI重新paint有关!!! 我碰到的问题是:按钮事件中用setJMenuBar(jmnUser)后,显示还是原来的菜单,要resize以后才能正确显示。请问如果是repaint问题如何解决? import javax.swing.*;import java.awt.event.*;public class A extends JFrame{ JButton jButton =new JButton("弹出消息"); public A(){ this.getContentPane().add(jButton); jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JDialog b = new B(); b.show(); } }); } public static void main(String[] args){ A a=new A(); a.setSize(400,300); a.show(); }}class B extends JDialog implements ActionListener{ JButton jButton; public B(){// 一些布局初始化 jButton=new JButton("弹出消息"); this.getContentPane().add(jButton); jButton.addActionListener(this); } public void actionPerformed(ActionEvent e){ new JOptionPane().showMessageDialog(null,"测试","警告",JOptionPane.OK_CANCEL_OPTION); return; }} org.w3c.dom.Document 关于接口 java编程思想中TestStram求解释 (int)(char)(byte)-1具体是怎么换算的? 寻找2~100之间的数的所有因数 新手报道,小小菜鸟向各位前辈问好 HashSet,TreeSet有什么用? 【求助】关于java的9个问题 关于JAVA类的调用问题,在线等待,谢谢 java的类和接口继承问题 那位老兄知道有jbuilder的教程下载,感激不尽,定给分? 关于package的问题 当jtable在model的值改变后如何让jtable自动刷新以显示新的数据?
new JOptionPane().showMessageDialog(this,"测试","警告");
System.exit(0);
}
import java.awt.*;
import java.awt.event.*;import javax.swing.*;public class Untitled2 extends JFrame implements ActionListener {
private JButton jButton1 = new JButton();
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(this,"测试","警告",JOptionPane.ERROR_MESSAGE);
return; }
public Untitled2() throws HeadlessException {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws HeadlessException {
Untitled2 untitled21 = new Untitled2();
untitled21.setSize(300,300);
untitled21.show();
}
private void jbInit() throws Exception {
jButton1.setText("OK");
jButton1.addActionListener(this);
this.getContentPane().add(jButton1, BorderLayout.CENTER);
}
}
class A extends JFrame{
public static void main(String[] args){
JDialog B=new JmyDialog(this);
B.show();
}
}
class JmyDialog extends JDialog implenents ActionListener{
JButton jButton;
Frame parent;
public B(Frame _parent){
super(_parent);
// 一些布局初始化
jButton=new JButton("弹出消息");
jButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(parent,"测试","警告");//这里的this应该是Frame才对
return;
}
import javax.swing.JDialog;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
public class A extends JFrame{
public static void main(String[] args){
JDialog b=new B();
b.show();
}
}
class B extends JDialog implements ActionListener{
JButton jButton;
public B(){
// 一些布局初始化
this.setBounds(100,100,200,200);
jButton=new JButton("弹出消息");
jButton.addActionListener(this);
this.getContentPane().add(jButton);
} public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(this,"测试");
}
}
我试了,没问题的
===>很幸运,还是没有问题.
需要用SwingUtilities.invokeLater()之类的方式来显示你的对话框
显示一个消息对话框,但是按消息对话框的那个确定按钮之后,消息框不消息,但是后面的语句都执行了,怀疑和UI重新paint有关!!!
请问如果是repaint问题如何解决?
import java.awt.event.*;public class A extends JFrame{
JButton jButton =new JButton("弹出消息");
public A(){
this.getContentPane().add(jButton);
jButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog b = new B();
b.show();
}
});
}
public static void main(String[] args){
A a=new A();
a.setSize(400,300);
a.show();
}
}
class B extends JDialog implements ActionListener{
JButton jButton;
public B(){
// 一些布局初始化
jButton=new JButton("弹出消息");
this.getContentPane().add(jButton);
jButton.addActionListener(this);
} public void actionPerformed(ActionEvent e){
new JOptionPane().showMessageDialog(null,"测试","警告",JOptionPane.OK_CANCEL_OPTION);
return;
}
}