以下一个java程序在eclipse中运行为何总是出现错误,而且这种错误在编辑窗口中没显示,大侠们帮帮忙吧!
packagebasegraph;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publiccl...
package basegraph;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class joption1 extends JFrame{
public static class showb implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==button1)
//显示警告信息对话框
JOptionPane.showMessageDialog(null, "A", "错误标志", JOptionPane.WARNING_MESSAGE);
else if(e.getSource()==button2)
JOptionPane.showConfirmDialog(null,"B", "确认", JOptionPane.YES_NO_OPTION);
else if(e.getSource()==button3)
JOptionPane.showInputDialog(null,"C","输入性息",JOptionPane.INFORMATION_MESSAGE);
}
}
//声明按钮面板和窗口
private static JButton button1,button2,button3;
private static JFrame f;
private static JPanel p;
public static void main(String []args){
f=new JFrame("显示按钮");
p=new JPanel();
button1=new JButton("A");
button1=new JButton("B");
button1=new JButton("C");
//注册事件监听器
button1.addActionListener(new showb());
button2.addActionListener(new showb());
button3.addActionListener(new showb());
//添加按钮到面板
p.add(button1);
p.add(button2);
p.add(button3);
//添加面板到窗口
f.getContentPane().add(p);
f.setSize(200,200);
f.setVisible(true);
}
} 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class joption1 extends JFrame{
public static class showb implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==button1)
//显示警告信息对话框
JOptionPane.showMessageDialog(null, "A", "错误标志", JOptionPane.WARNING_MESSAGE);
else if(e.getSource()==button2)
JOptionPane.showConfirmDialog(null,"B", "确认", JOptionPane.YES_NO_OPTION);
else if(e.getSource()==button3)
JOptionPane.showInputDialog(null,"C","输入性息",JOptionPane.INFORMATION_MESSAGE);
}
}
//声明按钮面板和窗口
private static JButton button1,button2,button3;
private static JFrame f;
private static JPanel p;
public static void main(String []args){
f=new JFrame("显示按钮");
p=new JPanel();
button1=new JButton("A");
button1=new JButton("B");
button1=new JButton("C");
//注册事件监听器
button1.addActionListener(new showb());
button2.addActionListener(new showb());
button3.addActionListener(new showb());
//添加按钮到面板
p.add(button1);
p.add(button2);
p.add(button3);
//添加面板到窗口
f.getContentPane().add(p);
f.setSize(200,200);
f.setVisible(true);
}
} 展开
2个回答
展开全部
package miniloanweb;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class joption1 extends JFrame {
public static class showb implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1)
// 显示警告信息对话框
JOptionPane.showMessageDialog(null, "A", "错误标志",
JOptionPane.WARNING_MESSAGE);
else if (e.getSource() == button2)
JOptionPane.showConfirmDialog(null, "B", "确认",
JOptionPane.YES_NO_OPTION);
else if (e.getSource() == button3)
JOptionPane.showInputDialog(null, "C", "输入性息",
JOptionPane.INFORMATION_MESSAGE);
}
}
// 声明按钮面板和窗口
private static JButton button1, button2, button3;
private static JFrame f;
private static JPanel p;
public static void main(String[] args) {
f = new JFrame("显示按钮");
p = new JPanel();
button1 = new JButton("A");
button2 = new JButton("B");
button3 = new JButton("C");
// 注册事件监听器
button1.addActionListener(new showb());
button2.addActionListener(new showb());
button3.addActionListener(new showb());
// 添加按钮到面板
p.add(button1);
p.add(button2);
p.add(button3);
// 添加面板到窗口
f.getContentPane().add(p);
f.setSize(200, 200);
f.setVisible(true);
}
}
错误改好了
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class joption1 extends JFrame {
public static class showb implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1)
// 显示警告信息对话框
JOptionPane.showMessageDialog(null, "A", "错误标志",
JOptionPane.WARNING_MESSAGE);
else if (e.getSource() == button2)
JOptionPane.showConfirmDialog(null, "B", "确认",
JOptionPane.YES_NO_OPTION);
else if (e.getSource() == button3)
JOptionPane.showInputDialog(null, "C", "输入性息",
JOptionPane.INFORMATION_MESSAGE);
}
}
// 声明按钮面板和窗口
private static JButton button1, button2, button3;
private static JFrame f;
private static JPanel p;
public static void main(String[] args) {
f = new JFrame("显示按钮");
p = new JPanel();
button1 = new JButton("A");
button2 = new JButton("B");
button3 = new JButton("C");
// 注册事件监听器
button1.addActionListener(new showb());
button2.addActionListener(new showb());
button3.addActionListener(new showb());
// 添加按钮到面板
p.add(button1);
p.add(button2);
p.add(button3);
// 添加面板到窗口
f.getContentPane().add(p);
f.setSize(200, 200);
f.setVisible(true);
}
}
错误改好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询