「菜单页面设计java」系统菜单设计
今天给各位分享菜单页面设计java的知识,其中也会对系统菜单设计进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
有没有java设计菜单
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Test_11 extends Frame implements ActionListener{ /**
* @param args
*/
MenuBar mb = null;
Menu m = null;
MenuItem mi = null; public Test_11() {
this.setBounds(100, 100, 400, 300);
this.setVisible(true);
mb = new MenuBar();
m = new Menu("文件");
mi = new MenuItem("打开");
mi.setShortcut(new MenuShortcut(KeyEvent.VK_O));
m.add(mi);
mb.add(m);
setMenuBar(mb);
mi.addActionListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} public static void main(String[] args) {
// TODO Auto-generated method stub
new Test_11();
} @Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}}
java设计一个创建二级菜单的程序。
100分,100分,100分, 重要的事情说三遍..~
我来1个参考案例
效果图
参考代码
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
// 本来继承自JFrame .实现ActionListener接口
public class TextFrame extends JFrame implements ActionListener {
private final JTextArea jta;
boolean isBold, isItalic;
public TextFrame() {
jta = new JTextArea();
jta.setLineWrap(true); // 自动换行
Font font = new Font(Font.DIALOG, Font.PLAIN, 26);
jta.setFont(font);
JScrollPane jsp = new JScrollPane(jta);// 会自动生成滚动条的面板
add(jsp);
//菜单栏的创建和设置
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem jmia01 = new JMenuItem("About");
jmia01.addActionListener(this);
JMenuItem jmia02 = new JMenuItem("Exit");
jmia02.addActionListener(this);
menuFile.add(jmia01);
menuFile.add(jmia02);
JMenu menuFormat = new JMenu("Format");
JMenu menuColor = new JMenu("Color");
JMenuItem jmib01 = new JMenuItem("Blue");
jmib01.addActionListener(this);
JMenuItem jmib02 = new JMenuItem("Red");
jmib02.addActionListener(this);
JMenuItem jmib03 = new JMenuItem("Yellow");
jmib03.addActionListener(this);
menuColor.add(jmib01);
menuColor.add(jmib02);
menuColor.add(jmib03);
JMenu menuFont = new JMenu("Font");
JMenuItem jmic01 = new JMenuItem("Bold");
jmic01.addActionListener(this);
JMenuItem jmic02 = new JMenuItem("Italic");
jmic02.addActionListener(this);
menuFont.add(jmic01);
menuFont.add(jmic02);
menuFormat.add(menuColor);
menuFormat.add(menuFont);
menuBar.add(menuFile);
menuBar.add(menuFormat);
setJMenuBar(menuBar);//设置菜单栏
setTitle("文本编辑窗口"); // 设置标题
setSize(520, 350);//设置窗口大小
setLocationRelativeTo(null);//设置窗口居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口点击关闭按钮时,退出
}
@Override
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();// 获取ActionCommand ,用于判断是哪一个按钮被点击了
if (cmd.equals("Exit")) {
System.exit(0);
} else if (cmd.equals("About")) {
JOptionPane.showMessageDialog(this, "程序版本Ver1.0", "About", JOptionPane.INFORMATION_MESSAGE);
} else if (cmd.equals("Blue")) {
jta.setForeground(Color.BLUE);
} else if (cmd.equals("Red")) {
jta.setForeground(Color.RED);
} else if (cmd.equals("Yellow")) {
jta.setForeground(Color.YELLOW);
} else if (cmd.equals("Bold")) { // 第一次选择Bold 会加粗,第二次选择Bold会取消加粗
isBold = !isBold;
if (isBold) {
jta.setFont(new Font(Font.DIALOG, Font.BOLD, 26));
} else {
jta.setFont(new Font(Font.DIALOG, Font.PLAIN, 26));
}
} else if (cmd.equals("Italic")) {
isItalic = !isItalic;
if (isItalic) {
jta.setFont(new Font(Font.DIALOG, Font.ITALIC, 26));
} else {
jta.setFont(new Font(Font.DIALOG, Font.PLAIN, 26));
}
}
}
public static void main(String[] args) {
new TextFrame().setVisible(true);// 创建窗口设置可见
}
}
谁会制作菜单界面JAVA
package java1;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Rectangle;
import java.awt.Font;
public class login extends JFrame
{
public login() {
try {
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args)
{
login frm=new login();
frm.setBounds(300,200,300,260);
frm.setVisible(true);
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
jLabel1.setForeground(Color.red);
jLabel1.setText("用户名");
jLabel1.setBounds(new Rectangle(25, 72, 68, 29));
jButton2.setBounds(new Rectangle(142, 159, 81, 30));
jButton2.setText("取消");
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton1.setBounds(new Rectangle(38, 159, 81, 29));
jButton1.setText("确定");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jTextField1.setBounds(new Rectangle(109, 79, 136, 23));
jPasswordField1.setBounds(new Rectangle(109, 115, 136, 23));
this.getContentPane().add(jLabel1);
jLabel3.setFont(new java.awt.Font("隶书", Font.PLAIN, 24));
jLabel3.setText("学 生 考 试 系 统");
jLabel3.setBounds(new Rectangle(22, 15, 268, 47));
this.getContentPane().add(jTextField1);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton1);
this.getContentPane().add(jLabel3);
this.getContentPane().add(jPasswordField1);
jLabel2.setForeground(Color.red);
jLabel2.setText("密码");
jLabel2.setBounds(new Rectangle(26, 112, 68, 29));
}
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
main2 wo=new main2();
int sum;
//判断权限的方法
public void success()
{
try{
ResultSet rs1;
String s1="select * from 管理权限 where name='"+jTextField1.getText()+"' and password='"+jPasswordField1.getText()+"'";
rs1=sqlcx.Rs_jiluji(s1);
rs1.first();
sum=Integer.parseInt((String)(rs1.getString(3)));
System.out.println(sum);
very();
}
catch(Exception c){System.out.println("success error");}
}
//根据权限设置窗口
public void very()
{
if (sum==1)
{JOptionPane.showOptionDialog(this, "您现在是以教师权限登陆", "登陆信息"br/ , JOptionPane.DEFAULT_OPTION,br/ JOptionPane.ERROR_MESSAGE,br/ null, null, null);br/ br/ }
else
{
JOptionPane.showOptionDialog(this, "你现在是以学生权限登陆", "登陆信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
wo.jButton2.setVisible(false);
wo.jButton3.setVisible(false);
wo.jButton4.setVisible(false);
wo.jButton5.setVisible(false);
wo.jButton6.setVisible(false);
wo.jButton7.setVisible(false);
wo.jButton8.setVisible(false);
wo.jMenu2.setVisible(false);
wo.jMenu3.setVisible(false);
wo.jMenu4.setVisible(false);
}
}
public void jButton1_actionPerformed(ActionEvent e)
{
//判断用户名是否为空
if (jTextField1.getText().length() == 0) {
JOptionPane.showOptionDialog(this, "用户名不能为空", "错误信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
//判断密码是否为空
else if (jPasswordField1.getText().length()==0)
{
JOptionPane.showOptionDialog(this,"密码不能为空", "错误信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
else
{
try
{
ResultSet rs;//声明记录集
String sql="select * from 管理权限 where name='"+jTextField1.getText()+"'";
rs = sqlcx.Rs_jiluji(sql);
if (rs.next())
{
if(jPasswordField1.getText().equals(rs.getString(2)))
{
success();
wo.setBounds(60,40,700,600);
wo.setVisible(true);
this.dispose();
}
else
{
JOptionPane.showOptionDialog(this,"密码错误", "错误信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
}
else
{
JOptionPane.showOptionDialog(this,"没有所要找的用户名", "错误信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
}
catch(Exception c){
JOptionPane.showOptionDialog(this,"连接数据库失败", "错误信息"
, JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, null, null);
}
}
}
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
}
java菜单怎么写?
希望有用吧
package mm;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class HelloWorld {
public static void main(String[] args){
JFrame w=new JFrame("SKH");
Container con=w.getContentPane();
//Color
con.setBackground(Color.pink);
//Location
w.setBounds(60, 100, 388, 308);
//可见性
w.setVisible(true);
//单击右上角容器的行为
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//创建菜单项
JMenuBar menubar=new JMenuBar();
JMenu menu,submenu;
JMenuItem a,b;
menu=new JMenu("菜单");
submenu=new JMenu("子菜单");
a=new JMenuItem("菜单项1");
b=new JMenuItem("菜单项2");
menu.add(a);
//添加分割符;
menu.addSeparator();
menu.add(b);
menu.addSeparator();
menu.add(submenu);
submenu.add(new JMenuItem("QWQ"));
menubar.add(menu);
w.setJMenuBar(menubar);
}
}
javaee如何设计菜单栏
JSP中菜单栏设计跟html一样,再用上javascript就可以了。
如果你想仿照某个网站来设计,可以使用浏览器中的开发人员选项,按F12就可以查看网页源代码了
菜单页面设计java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于系统菜单设计、菜单页面设计java的信息别忘了在本站进行查找喔。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。