永发信息网

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

答案:3  悬赏:20  手机版
解决时间 2021-07-30 10:10
  • 提问者网友:鼻尖触碰
  • 2021-07-29 18:51

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;
}

最佳答案
  • 五星知识达人网友:第四晚心情
  • 2021-07-29 19:15

首先 你给的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();
}
}

全部回答
  • 1楼网友:举杯邀酒敬孤独
  • 2021-07-29 21:54
没有main方法
  • 2楼网友:三千妖杀
  • 2021-07-29 20:35

改了可以运行

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(); } }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯