当前位置: 技术问答>java相关
希望帮忙看一下小代码,急!
来源: 互联网 发布时间:2015-08-08
本文导语: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.*; public class op { public static void main(String ars[]) { win obj=new win(); } } class win { JFrame fra; JPanel pan; JLabel lab;...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.*;
public class op
{
public static void main(String ars[])
{
win obj=new win();
}
}
class win
{
JFrame fra;
JPanel pan;
JLabel lab;
JButton but;
public win()
{
dengruButton dengruchick=new dengruButton();
fra=new JFrame();
pan=new JPanel();
lab=new JLabel("用户名:");
but=new JButton("ok");
but.addActionListener(dengruchick);
pan.add(lab);
pan.add(text);
pan.add(but);
fra.getContentPane().add(pan);
fra.setSize(200,100);
fra.show();
}
class dengruButton implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
JOptionPane.showConfirmDialog("出错","提示",JOptionPane.ERROR_MESSAGE);
}
}
}
编译时出错:
E:1op.java:41: cannot resolve symbol
symbol : method showConfirmDialog (java.lang.String,java.lang.String,int)
location: class javax.swing.JOptionPane
JOptionPane.showConfirmDialog("出错","提示",JOptionPane.ERROR_MESSAGE);
1 error
我想按下后提示出错信息。
希望指点一下,谢了!
import java.awt.*;
import java.awt.event.*;
import java.awt.*;
public class op
{
public static void main(String ars[])
{
win obj=new win();
}
}
class win
{
JFrame fra;
JPanel pan;
JLabel lab;
JButton but;
public win()
{
dengruButton dengruchick=new dengruButton();
fra=new JFrame();
pan=new JPanel();
lab=new JLabel("用户名:");
but=new JButton("ok");
but.addActionListener(dengruchick);
pan.add(lab);
pan.add(text);
pan.add(but);
fra.getContentPane().add(pan);
fra.setSize(200,100);
fra.show();
}
class dengruButton implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
JOptionPane.showConfirmDialog("出错","提示",JOptionPane.ERROR_MESSAGE);
}
}
}
编译时出错:
E:1op.java:41: cannot resolve symbol
symbol : method showConfirmDialog (java.lang.String,java.lang.String,int)
location: class javax.swing.JOptionPane
JOptionPane.showConfirmDialog("出错","提示",JOptionPane.ERROR_MESSAGE);
1 error
我想按下后提示出错信息。
希望指点一下,谢了!
|
1、showConfirmDialog(Component parentComponent, Object message)
2、showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
3、showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType)
4、showConfirmDialog(Component parentComponent, Object message,
String title, int optionType, int messageType, Icon icon)
2、showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
3、showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType)
4、showConfirmDialog(Component parentComponent, Object message,
String title, int optionType, int messageType, Icon icon)
|
JOptionPane.showConfirmDialog(null,"出错","提示",JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showConfirmDialog(null,"出错","提示",JOptionPane.ERROR_MESSAGE);
一般JPptionPane方法,第一个参数总是为:NULL
一般JPptionPane方法,第一个参数总是为:NULL
|
把win这个class改成下面的样子
class win implements ActionListener
{
JFrame fra;
JPanel pan;
JLabel lab;
JButton but;
public win()
{
fra = new JFrame();
pan = new JPanel();
lab = new JLabel("̞:");
but = new JButton("ok");
but.addActionListener(this);
pan.add(lab);
pan.add(but);
fra.getContentPane().add(pan);
fra.setSize(200, 200);
fra.show();
}
public void actionPerformed(ActionEvent evt)
{
JOptionPane op = new JOptionPane();
op.showConfirmDialog(fra, "³ö´í", "Ìáʾ", JOptionPane.ERROR_MESSAGE);
}
}
class win implements ActionListener
{
JFrame fra;
JPanel pan;
JLabel lab;
JButton but;
public win()
{
fra = new JFrame();
pan = new JPanel();
lab = new JLabel("̞:");
but = new JButton("ok");
but.addActionListener(this);
pan.add(lab);
pan.add(but);
fra.getContentPane().add(pan);
fra.setSize(200, 200);
fra.show();
}
public void actionPerformed(ActionEvent evt)
{
JOptionPane op = new JOptionPane();
op.showConfirmDialog(fra, "³ö´í", "Ìáʾ", JOptionPane.ERROR_MESSAGE);
}
}