?? mainframe.java
字號(hào):
package control.view;import control.view.product.ShowAllProducts;import control.view.prodin.ShowAllProdIn;import control.view.prodout.ShowAllProdOut;import control.view.store.ShowStore;import utils.GetResource;import javax.swing.*;import javax.swing.event.*;import java.awt.event.*;import java.awt.Dimension;import java.awt.Toolkit;import java.awt.image.*;import java.awt.Image;import java.util.Properties;public class MainFrame extends JFrame implements ActionListener{ Properties p=null; protected JMenuBar mb=null; protected JMenu m1=null; protected JMenu m2=null; protected JMenuItem m1_t1=null; protected JMenu m1_m2=null; protected JMenuItem m1_t2_t1=null; protected JMenuItem m1_t2_t2=null; protected JMenuItem m1_t2_t3=null; protected JMenuItem m1_t3=null; protected JMenuItem m2_t1=null; public void init(){ p=GetResource.getProperties(); mb=new JMenuBar(); m1=new JMenu(p.getProperty("menu1")); m2=new JMenu(p.getProperty("menu2")); m1_t1=new JMenuItem(p.getProperty("menu1.product")); m1_m2=new JMenu(p.getProperty("menu1.store")); m1_t2_t1=new JMenuItem(p.getProperty("menu1.store.in")); m1_t2_t2=new JMenuItem(p.getProperty("menu1.store.out")); m1_t2_t3=new JMenuItem(p.getProperty("menu1.store.sum")); m1_t3=new JMenuItem(p.getProperty("menu1.exit"),new ImageIcon("images/exit.gif")); m2_t1=new JMenuItem(p.getProperty("menu2.about"),new ImageIcon("images/help.gif")); Image icon=Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("/images/my.gif")); this.setIconImage(icon); } public void actionPerformed(ActionEvent e){ if(e.getSource() instanceof JMenuItem){ JMenuItem mi=(JMenuItem)e.getSource(); if(mi == m1_t1){ this.dispose(); new ShowAllProducts(p.getProperty("prod.title.all")); }else if(mi == m1_t2_t1){ this.dispose(); new ShowAllProdIn(p.getProperty("prodin.title.all")); }else if(mi == m1_t2_t2){ this.dispose(); new ShowAllProdOut(p.getProperty("prodout.title.all")); }else if(mi == m1_t2_t3){ this.dispose(); new ShowStore(p.getProperty("prodstore.title")); }else if(mi == m1_t3){ if( (JOptionPane.showConfirmDialog(this, new String(p.getProperty("msg.exit"))))== JOptionPane.YES_OPTION) { this.dispose(); } }else if(mi == m2_t1){ showDialog(p.getProperty("about1"),p.getProperty("about2"),p.getProperty("about3")); } } } public MainFrame(String title){ super(title); init(); m1_t1.addActionListener(this); m1_t2_t1.addActionListener(this); m1_t2_t2.addActionListener(this); m1_t2_t3.addActionListener(this); m1_t3.addActionListener(this); m2_t1.addActionListener(this); m1.add(m1_t1); m1.add(m1_m2); m1_m2.add(m1_t2_t1); m1_m2.add(m1_t2_t2); m1_m2.add(m1_t2_t3); m1.add(m1_t3); m2.add(m2_t1); mb.add(m1); mb.add(m2); this.setJMenuBar(mb); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); } public void showDialog(String title,String content1,String content2){ final JDialog jdg=new JDialog(this, title, true); JLabel jl1=new JLabel(content1); JLabel jl2=new JLabel(content2); JButton b_confirm=new JButton(p.getProperty("bt.sure")); b_confirm.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ jdg.dispose(); } }); jdg.getContentPane().setLayout(null); jl1.setBounds(50,30,200,50); jl2.setBounds(50,80,200,50); b_confirm.setBounds(85,120,100,35); jdg.getContentPane().add(jl1); jdg.getContentPane().add(jl2); jdg.getContentPane().add(b_confirm); setMid(250,250,jdg); jdg.setResizable(false); jdg.show(true); } public void setMid(int width,int height,java.awt.Window fra){ Dimension ds=Toolkit.getDefaultToolkit().getScreenSize(); int x=new Double( (ds.getWidth()-width)/2 ).intValue(); int y=new Double( (ds.getHeight()-height)/2 ).intValue(); fra.setBounds(x,y,width,height); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -