手写代码,还是痛苦点,但对布局有再深入的流程理解,
全IDE会更快速。。
package SwingGui.sky.com; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SimpleGui implements ActionListener { JTextArea text; public static void main(String [] args) { SimpleGui gui = new SimpleGui(); gui.go(); } public void go() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JButton button = new JButton("Just Click It"); button.addActionListener(this); text = new JTextArea(10, 20); text.setLineWrap(true); JScrollPane scroller = new JScrollPane(text); scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); panel.add(scroller); frame.getContentPane().add(BorderLayout.CENTER, panel); frame.getContentPane().add(BorderLayout.SOUTH, button); frame.setSize(350, 300); frame.setVisible(true); } public void actionPerformed(ActionEvent ev) { text.append("Button Clicked \n"); } }
时间: 2025-01-02 17:19:34