永发信息网

JAVA 的点菜系统怎么运不出来 谁来看看

答案:3  悬赏:20  手机版
解决时间 2021-07-30 10:10

import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class jiudian implements ActionListener,ItemListener
{
static JFrame f=null;

ButtonGroup bg;
JRadioButton r1,r2,r3,r4,r5;
JRadioButton c1,c2,c3,c4;
int op=0;
static int i=0;
public jiudian()
{ // Dialog = new JDialog(f,"选择您想要的桌号和您喜欢的菜",true);
f=new JFrame("选择您想要的桌号和您喜欢的菜");
Container dialogPane=f.getContentPane();
dialogPane.setLayout(new GridLayout(3,1));
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(1,5));
p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(
Color.green,4),"选择桌号",TitledBorder.CENTER,TitledBorder.TOP));
//单选按钮
r1=new JRadioButton("one");
r2=new JRadioButton("two");
r3=new JRadioButton("three");
r4=new JRadioButton("four");
r5=new JRadioButton("five");
p1.add(r1);
p1.add(r2);
p1.add(r3);
p1.add(r4);
p1.add(r5);
bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
bg.add(r3);
bg.add(r4);
bg.add(r5);
r1.addItemListener(this);
r2.addItemListener(this);
r3.addItemListener(this);
r4.addItemListener(this);
r5.addItemListener(this);
JPanel p2=new JPanel();
p2.setLayout(new GridLayout(4,1));
p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(
Color.green,4),"选择您喜欢的菜",TitledBorder.CENTER,TitledBorder.TOP));
c1=new JRadioButton(" 小鸡炖蘑菇,价格为:25元/份");
c2=new JRadioButton(" 青椒炒肉, 价格为:18元/份");
c3=new JRadioButton(" 东北火锅, 价格为:36元/份");
c4=new JRadioButton(" 豆腐炖鱼头,价格为:36元/份");
p2.add(c1);
p2.add(c2);
p2.add(c3);
p2.add(c4);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
JPanel p3=new JPanel();
p3.setLayout (new GridLayout(1,3));
JButton button1=new JButton("确定");
JButton button2=new JButton("结帐");
JButton button3=new JButton("取消");
p3.add(button1);
p3.add(button2);
p3.add(button3);
button1.addActionListener (this);
button2.addActionListener (this);
button3.addActionListener (this);
dialogPane.add(p1,BorderLayout.NORTH);
dialogPane.add(p2,BorderLayout.CENTER);
dialogPane.add(p3,BorderLayout.SOUTH);
f.getRootPane ().setDefaultButton (button1);
f.pack();

f.setBounds(250,250,400,400);
f.setVisible (true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==r1) op=1;
if(e.getSource()==r2) op=2;
if(e.getSource()==r3) op=3;
if(e.getSource()==r4) op=4;
if(e.getSource()==r5) op=5;
if(e.getSource()==c1) i=1;
if(e.getSource()==c2) i=2;
if(e.getSource()==c3) i=3;
if(e.getSource()==c4) i=4;
}

最佳答案

首先 你给的jiudian类 没有写完整 结尾少了一个“}”


其次 你implements 了ActionListener 但是没有实现actionPerformed方法


最后 你没有main方法 没有new jiudian(); 当然不会出来界面



修改后的程序如下 但是 actionPerformed方法 没有写具体实现 因为不知道你想要什么效果



public class jiudian implements ActionListener, ItemListener {
static JFrame f = null;


ButtonGroup bg;
JRadioButton r1, r2, r3, r4, r5;
JRadioButton c1, c2, c3, c4;
int op = 0;
static int i = 0;
public jiudian() { // Dialog = new JDialog(f,"选择您想要的桌号和您喜欢的菜",true);
f = new JFrame("选择您想要的桌号和您喜欢的菜");
Container dialogPane = f.getContentPane();
dialogPane.setLayout(new GridLayout(3, 1));
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(1, 5));
p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.
createLineBorder(
Color.green, 4), "选择桌号", TitledBorder.CENTER,
TitledBorder.TOP));
//单选按钮
r1 = new JRadioButton("one");
r2 = new JRadioButton("two");
r3 = new JRadioButton("three");
r4 = new JRadioButton("four");
r5 = new JRadioButton("five");
p1.add(r1);
p1.add(r2);
p1.add(r3);
p1.add(r4);
p1.add(r5);
bg = new ButtonGroup();
bg.add(r1);
bg.add(r2);
bg.add(r3);
bg.add(r4);
bg.add(r5);
r1.addItemListener(this);
r2.addItemListener(this);
r3.addItemListener(this);
r4.addItemListener(this);
r5.addItemListener(this);
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(4, 1));
p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.
createLineBorder(
Color.green, 4), "选择您喜欢的菜", TitledBorder.CENTER,
TitledBorder.TOP));
c1 = new JRadioButton(" 小鸡炖蘑菇,价格为:25元/份");
c2 = new JRadioButton(" 青椒炒肉, 价格为:18元/份");
c3 = new JRadioButton(" 东北火锅, 价格为:36元/份");
c4 = new JRadioButton(" 豆腐炖鱼头,价格为:36元/份");
p2.add(c1);
p2.add(c2);
p2.add(c3);
p2.add(c4);
c1.addItemListener(this);
c2.addItemListener(this);
c3.addItemListener(this);
c4.addItemListener(this);
JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(1, 3));
JButton button1 = new JButton("确定");
JButton button2 = new JButton("结帐");
JButton button3 = new JButton("取消");
p3.add(button1);
p3.add(button2);
p3.add(button3);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
dialogPane.add(p1, BorderLayout.NORTH);
dialogPane.add(p2, BorderLayout.CENTER);
dialogPane.add(p3, BorderLayout.SOUTH);
f.getRootPane().setDefaultButton(button1);
f.pack();


f.setBounds(250, 250, 400, 400);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
}


public void itemStateChanged(ItemEvent e) {
if (e.getSource() == r1)
op = 1;
if (e.getSource() == r2)
op = 2;
if (e.getSource() == r3)
op = 3;
if (e.getSource() == r4)
op = 4;
if (e.getSource() == r5)
op = 5;
if (e.getSource() == c1)
i = 1;
if (e.getSource() == c2)
i = 2;
if (e.getSource() == c3)
i = 3;
if (e.getSource() == c4)
i = 4;
}


public void actionPerformed(ActionEvent e) {
}

public static void main(String[] args){
new jiudian();
}
}

全部回答
没有main方法

改了可以运行

import java.sql.*; import javax.swing.*; import java.awt.*; import java.awt.event.*;

import javax.swing.border.*; public class jiudian implements ActionListener,ItemListener { static JFrame f=null;

ButtonGroup bg; JRadioButton r1,r2,r3,r4,r5; JRadioButton c1,c2,c3,c4; int op=0; static int i=0; public jiudian() { // Dialog = new JDialog(f,"选择您想要的桌号和您喜欢的菜",true); f=new JFrame("选择您想要的桌号和您喜欢的菜"); Container dialogPane=f.getContentPane(); dialogPane.setLayout(new GridLayout(3,1)); JPanel p1=new JPanel(); p1.setLayout(new GridLayout(1,5)); p1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder( Color.green,4),"选择桌号",TitledBorder.CENTER,TitledBorder.TOP)); //单选按钮 r1=new JRadioButton("one"); r2=new JRadioButton("two"); r3=new JRadioButton("three"); r4=new JRadioButton("four"); r5=new JRadioButton("five"); p1.add(r1); p1.add(r2); p1.add(r3); p1.add(r4); p1.add(r5); bg=new ButtonGroup(); bg.add(r1); bg.add(r2); bg.add(r3); bg.add(r4); bg.add(r5); r1.addItemListener(this); r2.addItemListener(this); r3.addItemListener(this); r4.addItemListener(this); r5.addItemListener(this); JPanel p2=new JPanel(); p2.setLayout(new GridLayout(4,1)); p2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder( Color.green,4),"选择您喜欢的菜",TitledBorder.CENTER,TitledBorder.TOP)); c1=new JRadioButton(" 小鸡炖蘑菇,价格为:25元/份"); c2=new JRadioButton(" 青椒炒肉, 价格为:18元/份"); c3=new JRadioButton(" 东北火锅, 价格为:36元/份"); c4=new JRadioButton(" 豆腐炖鱼头,价格为:36元/份"); p2.add(c1); p2.add(c2); p2.add(c3); p2.add(c4); c1.addItemListener(this); c2.addItemListener(this); c3.addItemListener(this); c4.addItemListener(this); JPanel p3=new JPanel(); p3.setLayout (new GridLayout(1,3)); JButton button1=new JButton("确定"); JButton button2=new JButton("结帐"); JButton button3=new JButton("取消"); p3.add(button1); p3.add(button2); p3.add(button3); button1.addActionListener (this); button2.addActionListener (this); button3.addActionListener (this); dialogPane.add(p1,BorderLayout.NORTH); dialogPane.add(p2,BorderLayout.CENTER); dialogPane.add(p3,BorderLayout.SOUTH); f.getRootPane ().setDefaultButton (button1); f.pack();

f.setBounds(250,250,400,400); f.setVisible (true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); } public void itemStateChanged(ItemEvent e) { if(e.getSource()==r1) op=1; if(e.getSource()==r2) op=2; if(e.getSource()==r3) op=3; if(e.getSource()==r4) op=4; if(e.getSource()==r5) op=5; if(e.getSource()==c1) i=1; if(e.getSource()==c2) i=2; if(e.getSource()==c3) i=3; if(e.getSource()==c4) i=4; } public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } public static void main(String []as){ jiudian a=new jiudian(); } }

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
如何制作蜂蜜柚子茶?
sj哥哥们的 综艺节目
荷塘区株洲华龙幼稚园地址在什么地方,想今天
字母键盘锁定了怎么办,键盘锁住了,怎么解锁
郑州女包哪里比光彩便宜
本姑娘86年6月7日出生,阴历五月初一,想占卜
喝碧生源肠清茶有助减肥吗?会反弹吗?
一年中什么时候机票最便宜?
在淘宝网注册一个帐户许要那些证件?
买安全套你会选择哪购买?
我历史考试不及格用英语怎么说
当面包和火腿不能兼得时,你会选择哪个?
安宁 吉他谱
我的DNF老在读取中怎么办?那个文件也删除了
工作职能是什么意思,简历首页写什么,工作职
推荐资讯
2010年国家公务员考试我能报哪些?
系统怎么分为3个盘
To allow teenagers to study in groups duri
如何解决交通违规现象
qq自由幻想里我有946个仙点,该换点什么最转
通许县开封通许县民防局怎么去啊,谁知道地址
手机号码隐藏
双清区邵阳飞越通讯怎么去啊,谁知道地址啊
在你母亲最伤心的时候.你会怎么办?
会员到期 会被取消特权吗
济源市济源汤浅蓄电池地址有谁知道?有点事想
核舟记作业本答案
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?