JFrame是Frame的子类 Frame is part of java.awt package and exists since JDK1.0. JFrame is part of javax.swing package and exists since JDK1.1.3 or something. Frame extends Window.JFrame extends Frame. You can directly add components to Frame. You add comp…
1. 一个简单的swing public class Test(){ public static void main(String[] args){ JFrame frame = new JFrame(); JPanel panel = new JPanel(); JTextArea textArea = new JTextArea(); panel.setLayout(new GridLayout()); textArea.setText("test"); //当TextArea里的…
package common; import javax.swing.JFrame; import javax.swing.SwingUtilities; /*2015-5-26*/ public class SwingConsole { public static void run(final JFrame frame,final int width,final int height){ SwingUtilities.invokeLater(new Runnable() { @Override…
写了Java这么久,居然发现想手写一个带网格袋布局的JFrame,还不记得怎么写,写了这么多代码真不敢说记得所有细节. 幸好,只要记清楚概念就能快速开发.首先,明确一下3种容器类的差别和用途: No. 区别 1 Panel JPanel用于放置其他控件,也包含其他panels. 2 Frame JFrame 是包含 title and a border的第一层级的容器,其中通过布局设置JPanel或其他控件的位置. 3 Window JWindow是不包含 title and a border的…
import javax.swing.*;import java.awt.*;import java.awt.event.*; public class Exercise16_22 extends JFrame { final static int NUMBER_OF_SLOTS = 9; final static int NUMBER_OF_ROWS = NUMBER_OF_SLOTS - 2; private int shift = 0; private int[] slots = new…