日期:2014-05-20 浏览次数:20796 次
package GUI_Demo1;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GUIDC1 {
public static void main(String []args)
{
/*
* 为了方便以后需该,定义4个窗体大小的变量
* 分别是:jfx,jfy,jfw,jfh
*/
int jfx = 30, jfy = 30, jfwidth = 600, jfheight = 600 ;
JFrame jf = new JFrame();
jf.setBounds(jfx,jfy,jfwidth,jfheight);
//jf.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
JPanel jp = new JPanel() ;
jp.setBackground(Color.YELLOW);
jp.setBounds(jfx, jfy, jfwidth, jfheight);
jf.add(jp);//为什么没有出现黄色?
JButton jb[] = new JButton[6];
for(int i=0; i<6; i++)
{
jb[i] = new JButton("流式布局按钮"+(i+1)) ;
}
for(int i=0; i<6; i++)
{
jp.add(jb[i]);
}
System.out.println("显示窗体请按[1],不显示请按[2]");
Scanner sa =new Scanner(System.in);
int sa_i = sa.nextInt();
boolean b = false ;
if( 1 == sa_i )
{
b = true ;
}else if( 2 == sa_i )
{
b = false ;
}else
{
System.out.println("你的输入不符合规范!");
}
jf.setVisible(b);
}
}
package GUI_Demo1;
import java.awt.Color;
import java.awt.FlowLayout;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class GUIDC1 {
public static void main(String[] args) {
/*
* 为了方便以后需该,定义4个窗体大小的变量
* 分别是:jfx,jfy,jfw,jfh
*/
int jfx = 30, jfy = 30, jfwidth = 600, jfheight = 600;
JFrame jf = new JFrame();
jf.setBounds(jfx, jfy, jfwidth, jfheight);
jf.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
jf.getContentPane().setBackground(Color.YELLOW);
JPanel jp = new JPanel();
jp.setOpaque(false);
// jp.setBackground(Color.YELLOW);
// jp.setBounds(jfx, jfy, jfwidth, jfheight);
jf.add(jp);//为什么没有出现黄色?
JButton jb[] = new JButton[6];
for(int i = 0; i < 6; i++) {
jb[i] = new JButton("流式布局按钮" + (i + 1));
}
for(int i = 0; i < 6; i++) {