javaswing点餐系统(java swing程序怎么运行)

本文目录
- java swing程序怎么运行
- JAVA Swing类的一个问题,怎么让一个菜单项能在两个菜单里共存
- 用java swing 做一个点菜系统,如何将菜单做成按钮的形式,并将图片显示在按钮上
- 怎样用Java swing 来做一个点餐系统里面的订单模块,只需要窗体,不需要其他效果菜鸟求代码
java swing程序怎么运行
import java.awt.*;
import javax.swing.*;
public class GUI extends JFrame{
private JMenuBar mb=new JMenuBar();
private JMenu mm=new JMenu("文件");
private JMenuItem mi1=new JMenuItem("粘贴");
private JMenuItem mi2=new JMenuItem("复制");
private JLabel l=new JLabel();
public GUI(){
this.setLayout(null);
mm.add(mi1);
mm.add(mi2);
mb.add(mm);
this.setJMenuBar(mb);
l.setText("我的第一个图形用户界面");
l.setBounds(10,10,450,30);
this.getContentPane().add(l);
this.setBounds(330,250,500,150);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args){
new GUI();
}
}
JAVA Swing类的一个问题,怎么让一个菜单项能在两个菜单里共存
public class NewJFrame2 extends javax.swing.JFrame {
/** Creates new form NewJFrame2 */
public NewJFrame2() {
initComponents();
Action action = new AbstractAction("别点了") {
public void actionPerformed(ActionEvent e) {
System.out.println(e.getSource());
}
};
this.jMenu1.add(action);
this.jMenu2.add(action);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// 《editor-fold defaultstate="collapsed" desc="Generated Code"》
private void initComponents() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jMenuBar1.setName("jMenuBar1"); // NOI18N
jMenu1.setText("File");
jMenu1.setName("jMenu1"); // NOI18N
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenu2.setName("jMenu2"); // NOI18N
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
pack();
}// 《/editor-fold》
/**
* @param args the command line arguments
*/
public static void main(String args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame2().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
// End of variables declaration
}
把视野放开,按钮作用是激发action,即便你两个一样的按钮目的还是为了激发同一个action,那么实际上你要只是一个action对应两个菜单而已,这就是解决方案。同样如果要两个一模一样的表格你大可不必要求一个JTable两个父容器,这是不可能的,更好的方法是两个JTable 共用一个TableModle就可以了,甚至是多个表格共用都没有问题。这种思想也是mvc的一部分,界面永远都是不同的,相同的只是数据和处理流程。上面的代码是Netbeans自动生成的,所以看起来很乱。
用java swing 做一个点菜系统,如何将菜单做成按钮的形式,并将图片显示在按钮上
这个应该不难的,按钮就是用Jbutton来实现,jbutton上是可以嵌入图片的,把按钮放在Jpanel,再来布局,会好看一些。
怎样用Java swing 来做一个点餐系统里面的订单模块,只需要窗体,不需要其他效果菜鸟求代码
绑定一个事件到被点击的窗体或控件,点击后获取控件信息,然后传参给一个自定义的窗体类的构造函数,如A = new oneDialog(参数1,参数2....);然后A.setVisible(true)。大概就是这个样子,有不懂得可以继续问

本文相关文章:
swap指令是什么意思(swap是什么高手帮解释下~~谢谢了~)
2026年9月19日 15:20
eclipse安装swing组件(swing插件怎么在网上下载)
2026年7月10日 01:10
更多文章:
avantage怎么设置为中文(Avantage安装丢失GIT)
2026年10月15日 03:00
activex控件未注册怎么办(登陆视频监控网页时提示activex控件未注册,怎么解决)
2026年10月14日 20:30
excel连接sql数据库教程(excel怎么连接sql数据库)
2026年10月14日 19:40







