问题就是在不同地方使用setVisible最终效果不同,下面有代码和效果图
package mvc; import javax.swing.JFrame; import javax.swing.*; import java.awt.*; /** * Created by Smith on 2016/10/15. */ public class MvcTest { static final int WIDTH = 500; static final int HEIGHT = 600; public static void main(String[] args) { JFrame jf = new JFrame("Hello"); jf.setSize(WIDTH,HEIGHT); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setVisible(true); JPanel jp = new JPanel(); jf.setContentPane(jp); JButton btn1 = new JButton("WEST"); BorderLayout lay = new BorderLayout(); jf.setLayout(lay); jp.add(btn1,"West"); //jf.setVisible(true); } }
生成效果:
接下来是正常结果的代码
package mvc; import javax.swing.JFrame; import javax.swing.*; import java.awt.*; /** * Created by Smith on 2016/10/15. */ public class MvcTest { static final int WIDTH = 500; static final int HEIGHT = 600; public static void main(String[] args) { JFrame jf = new JFrame("Hello"); jf.setSize(WIDTH,HEIGHT); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //jf.setVisible(true); JPanel jp = new JPanel(); jf.setContentPane(jp); JButton btn1 = new JButton("WEST"); BorderLayout lay = new BorderLayout(); jf.setLayout(lay); jp.add(btn1,"West"); jf.setVisible(true); } }
付费偷看金额在0.1-10元之间
一周热门 更多>