📄 initgui.java
字号:
import javax.swing.*;import java.awt.event.*;import java.awt.BorderLayout;import java.awt.Font;import static java.awt.Font.*;import java.awt.Color;public class initGUI extends JFrame implements ActionListener { private JDialog aboutBox; public initGUI(String title) { super(title); super.setBounds(824, 0, 200, 600); super.setJMenuBar(drawMenu()); drawFrame(); super.setDefaultCloseOperation(EXIT_ON_CLOSE); super.setVisible(true); } public void drawFrame() { JPanel b = new JPanel(); String fakeBuddies[] = { "macRules1990", "linuxMan87", "zachogden" }; JLabel label = new JLabel("Buddy List:"); JList buddyList = new JList(); JTextArea msgViewer = new JTextArea(); String fakeMsgs = "Message Viewer:\nlinuxMan87:\nHey man, we still going to that one thing?\n\nmacRules1990:\nDude, Mac Rules."; msgViewer.setText(fakeMsgs); msgViewer.setEditable(false); msgViewer.setLineWrap(true); label.setFont(new Font("Arial", ITALIC, 12)); buddyList.setFont(new Font("Arial", PLAIN, 12)); buddyList.setListData(fakeBuddies); JTextArea aArea = new JTextArea(); JScrollPane sPane = new JScrollPane(aArea); this.getContentPane().add(label, BorderLayout.NORTH); this.getContentPane().add(buddyList, BorderLayout.CENTER); this.getContentPane().add(msgViewer, BorderLayout.SOUTH); } public JMenuBar drawMenu() { JMenuBar menu = new JMenuBar(); JMenu buddies = new JMenu("Buddies"); JMenu prefs = new JMenu("Preferences"); JMenu help = new JMenu("Help"); JMenuItem about = new JMenuItem("About"); about.addActionListener(new newListener("About")); JMenuItem UC = new JMenuItem("Under Construction!"); JMenuItem quit = new JMenuItem("Quit"); quit.addActionListener(new newListener("Quit")); JMenuItem options = new JMenuItem("Options..."); options.addActionListener(new newListener("Options")); buddies.setMnemonic('B'); prefs.setMnemonic('P'); options.setMnemonic('O'); help.setMnemonic('H'); buddies.add(UC); buddies.add(quit); prefs.add(options); help.add(about); menu.add(buddies); menu.add(prefs); menu.add(help); return menu; } private void aboutBox() { aboutBox = new JDialog(this, "About Java IM", true); JPanel msgPanel = new JPanel(); JPanel btnPane = new JPanel(); JTextArea jArea = new JTextArea(); jArea.setText("Java IM Version 0.0.1\n" + "Copyright The Java IM Development Team\n" + "Distributed under the most recent verison of\n" + "the GNU General Public License."); jArea.setEditable(false); msgPanel.add(jArea); JButton ok = new JButton("OK"); btnPane.add(ok); ok.addActionListener(this); aboutBox.setLocation(320, 240); aboutBox.getContentPane().add(msgPanel); aboutBox.getContentPane().add(btnPane, BorderLayout.SOUTH); aboutBox.setDefaultCloseOperation(DISPOSE_ON_CLOSE); aboutBox.pack(); aboutBox.setVisible(true); return; } /* action listener for about box */ public void actionPerformed(ActionEvent e) { aboutBox.setVisible(false); aboutBox.dispose(); } /* Our very own custom made action listener! */ class newListener implements ActionListener { private String name; public newListener(String n) { name = n; } public void actionPerformed(ActionEvent e) { if(name == "Quit") { System.exit(0); } if(name == "About") { aboutBox(); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -