📄 demojapplet.java
字号:
import java.awt.BorderLayout;import java.awt.Dimension;import javax.swing.*;import java.awt.*;import java.io.*;import java.awt.event.*;import javax.swing.event.*;/*** This code was edited or generated using CloudGarden's Jigloo* SWT/Swing GUI Builder, which is free for non-commercial* use. If Jigloo is being used commercially (ie, by a corporation,* company or business for any purpose whatever) then you* should purchase a license for each developer using Jigloo.* Please visit www.cloudgarden.com for details.* Use of Jigloo implies acceptance of these licensing terms.* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.*/public class DemoJApplet extends JFrame { TrayIconUtil util=TrayIconUtil.getDefaultTrayIconUtil(); private JPopupMenu popup = new JPopupMenu("Test PopupMenu"); private JMenuItem item_SH = new JMenuItem(); private JMenuItem item_Exit = new JMenuItem(new ExitAction()); private JLabel jLabelUser; private JTextField jTextFieldUser; private JPasswordField jPasswordFieldPass; private JCheckBox jCheckBoxStartWithWindows; private JButton jButtonReg; private JButton jButtonLogin; private JLabel jLabelPass; /** * Auto-generated main method to display this * JApplet inside a new JFrame. */ public static void main(String[] args) { DemoJApplet inst = new DemoJApplet(); inst.show(); } public DemoJApplet() { super(); initGUI(); } private void jbInit() throws Exception { item_SH.setText("Hide"); item_SH.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { item_SH_actionPerformed(e); } }); popup.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent e) { item_SH.setText(isVisible()?"Hide":"Show"); item_SH.setMnemonic(isVisible()?'H':'S'); } public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } public void popupMenuCanceled(PopupMenuEvent e) { } }); popup.add(item_SH); popup.addSeparator(); popup.add(item_Exit); util.initTrayIcon("Demo",new File("tray.gif"),this,popup); util.showTrayIcon(); } private void initGUI() { try { jbInit(); getContentPane().setLayout(null); this.setSize(211, 153); this.setPreferredSize(new java.awt.Dimension(211, 153)); { jLabelUser = new JLabel(); getContentPane().add(jLabelUser); jLabelUser.setText("用户名:"); jLabelUser.setBounds(14, 14, 56, 14); } { jTextFieldUser = new JTextField(); getContentPane().add(jTextFieldUser); jTextFieldUser.setBounds(70, 7, 119, 21); } { jLabelPass = new JLabel(); getContentPane().add(jLabelPass); jLabelPass.setText("密码:"); jLabelPass.setBounds(14, 35, 56, 14); } { jButtonLogin = new JButton(); getContentPane().add(jButtonLogin); jButtonLogin.setText("\u767b\u9646"); jButtonLogin.setBounds(21, 63, 63, 28); jButtonLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out .println("jButtonLogin.actionPerformed, event=" + evt); //TODO add your code for jButtonLogin.actionPerformed item_SH_actionPerformed(evt); } }); } { jButtonReg = new JButton(); getContentPane().add(jButtonReg); jButtonReg.setText("\u6ce8\u518c"); jButtonReg.setBounds(105, 63, 63, 28); } { jCheckBoxStartWithWindows = new JCheckBox(); getContentPane().add(jCheckBoxStartWithWindows); jCheckBoxStartWithWindows.setText("\u968fwindows\u542f\u52a8"); jCheckBoxStartWithWindows.setBounds(21, 91, 133, 28); } { jPasswordFieldPass = new JPasswordField(); getContentPane().add(jPasswordFieldPass); jPasswordFieldPass.setBounds(70, 35, 119, 21); } } catch (Exception e) { e.printStackTrace(); } } protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { this.setExtendedState(ICONIFIED); return; } super.processWindowEvent(e); } void item_SH_actionPerformed(ActionEvent e) { this.setVisible(!this.isVisible()); if(isVisible()){ if(this.getExtendedState()==ICONIFIED){ this.setExtendedState(NORMAL); } } } static { try { //长得像windows程序 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { } }}class ExitAction extends AbstractAction{ public ExitAction(){ super("Exit"); super.putValue(Action.MNEMONIC_KEY,new Integer('X')); } public void actionPerformed(ActionEvent e) { TrayIconUtil.getDefaultTrayIconUtil().closeTrayIcon(); System.exit(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -