package 学生信息管理系统;
public class CMenu {
public static void main(String[] args) {
// TODO 自动生成的方法存根
WindowMenu window=new WindowMenu("学生信息管理系统",200,200,1000,1000);
}
}
import javax.swing.*;
import java.awt.*;
public class Prctise1_0 {
public static void main(String args[]) {
JFrame window1=new JFrame("The frist window");
JFrame window2=new JFrame("The second window");
ImageIcon icon=new ImageIcon("C:\\\\Users\\\\Administrator\\\\Desktop\\\\敏琪.jpg");
JLabel lable=new JLabel(icon);
Container con=window1.getContentPane();
window2.add(lable);
window1.setBounds(10, 50, 900, 900);
window2.setBounds(90, 100, 900, 900);
window1.setVisible(true);
window1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
window2.setVisible(true);
window2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class WindowOperation extends JFrame{
JTextField inputNumberOne,inputNumberTwo; //声明输入框对象
JComboBox chioceFuhao; //声明下拉列表对象
JTextArea textShow; //声明输入块对象
JButton button;//设置按钮对象
JLabel background;
ImageIcon icon;
OperatorListener operator; //声明ActionListener类型监视器
ComputerListener computer;//声明ItemEventListener类型监视器
public WindowOperation() {
init();
getLayeredPane().setLayout(null);
add(background);
pack();
setVisible(true); //设置可视化模式
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置关闭模式
}
void init(){
Box Hbox=Box.createVerticalBox();
JTextField b=new JTextField("运算结果:",30);
setLayout(new FlowLayout());
icon=new ImageIcon("C:\\Users\\Administrator\\Desktop\\敏琪.jpg");
background =new JLabel(icon);
background.setIcon(icon);
inputNumberOne=new JTextField(5); //设置1号输入框长度
inputNumberTwo=new JTextField(5); //设置2号输入框长度
chioceFuhao=new JComboBox();
button=new JButton("计算"); //设置按钮名称
chioceFuhao.addItem("选择运算符:");
getLayeredPane().add(background,new Integer(Integer.MIN_VALUE));
String []a= {"+","-","*","/"}; //给下拉列表添加组件
for(int i=0;i
}
textShow=new JTextArea(10,30);//设置输入块长宽
operator=new OperatorListener(); //监视ItemEvent事件的监视器
computer=new ComputerListener();//监视ActionEvert事件的监视器
operator.setJComboBox(chioceFuhao); //让监视器operator监视下拉列表
operator.setWorkTogether(computer); //监视器operator调用接口方法作出动作
computer.setJTextFieldOne(inputNumberOne); //让监视器computer监视输入框1
computer.setJTextArea(textShow); //让监视器computer监视输入块
computer.setJTextFieldTwo(inputNumberTwo);//让监视器computer监视输入框2
chioceFuhao.addItemListener(operator); //注册监视器:设置能触发监视器operator的组件->chioceFuhao
button.addActionListener(computer); //注册监视器:设置能触发监视器computer的组件->button
add(inputNumberOne); //把组件添加到容器中
add(chioceFuhao); //把组件添加到容器中
add(inputNumberTwo); //把组件添加到容器中
add(button); //把组件添加到容器中
Hbox.add(b);
add(Hbox);
add(new JScrollPane(textShow));//向输入块添加滚动窗格
}
}
package 学生信息管理系统;
import javax.swing.*;
import java.awt.Image;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class WindowMenu extends JFrame{
JMenuBar menubar;
JMenu menu1,menu2,menu3,submenu1,submenu2,submenu3,submenu21;
JMenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10,item11,item12,item13;
public WindowMenu() {}
public WindowMenu(String s,int a,int b,int c,int d) {
init(s);
setLocation(a,b);
setSize(c,d);
setVisible(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
ImageIcon ico;
JLabel label;
ico=new ImageIcon("C:\\Users\\Administrator\\Desktop\\敏琪.jpg");
label=new JLabel(ico);
add(label);
//setBounds(50, 50, 500, 500);//设置窗口位置及背景大小
label.setLayout(null);
setSize(ico.getIconWidth(),ico.getIconHeight());
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setVisible(true);
}
void init(String s) {
setTitle(s);
int width=15;
int height=15;
menubar=new JMenuBar();
menu1=new JMenu("文件");
menu2=new JMenu("编辑");
menu3=new JMenu("帮助");
submenu1=new JMenu("切换工作空间");
submenu2=new JMenu("求助");
submenu21=new JMenu("返回");
//submenu21=new JMenu("");
ImageIcon icon1=new ImageIcon("C:\\Users\\Administrator\\Desktop\\敏琪.jpg");
icon1.setImage(icon1.getImage().getScaledInstance(width, height,Image.SCALE_DEFAULT));
item1=new JMenuItem("新建",icon1);
ImageIcon icon2=new ImageIcon("C:\\Users\\Administrator\\Desktop\\敏琪.jpg");
icon2.setImage(icon2.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT));
item2=new JMenuItem("打开",icon2);
ImageIcon icon3=new ImageIcon("C:\\Users\\Administrator\\Desktop\\敏琪.jpg");
icon3.setImage(icon3.getImage().getScaledInstance(width, height,Image.SCALE_REPLICATE));
item3=new JMenuItem("另存为",icon3);
item4=new JMenuItem("退出",icon3);
item5=new JMenuItem("复制",icon3);
item6=new JMenuItem("删除",icon3);
item7=new JMenuItem("关于系统",icon3);
item8=new JMenuItem("空间1",icon3);
item9=new JMenuItem("求助老师",icon3);
item10=new JMenuItem("求助同学",icon3);
//item11=new JMenuItem("返回",icon3);
item12=new JMenuItem("返回上一步",icon3);
item13=new JMenuItem("返回第一步",icon3);
item1.setAccelerator(KeyStroke.getKeyStroke("A"));
item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
menu1.add(item1);
menu1.addSeparator();
menu2.addSeparator();
menu3.addSeparator();
menu1.add(item2);
menu1.add(item3);
menu1.add(item4);
menu1.add(submenu1);
menu2.add(item5);
menu2.add(item6);
menu3.add(item7);
menu3.add(submenu2);
submenu2.add(item9);
submenu2.add(item10);
submenu2.add(submenu21);
submenu21.add(item12);
submenu21.add(item13);
submenu1.add(item8);
menubar.add(menu1);
menubar.add(menu2);
menubar.add(menu3);
setJMenuBar(menubar);
}
}
运行截图: