Home >Java >javaTutorial >Basic operation statements of Java forms

Basic operation statements of Java forms

一个新手
一个新手Original
2017-10-10 09:47:391934browse

package com.swift;
    import java.awt.Color;
    import java.awt.GridLayout;
    import java.util.Random;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class RP_Frame extends JFrame {
    private static final long serialVersionUID = 1L;
    public RP_Frame() {
    setBounds(200, 200, 500, 300);
    //设置窗体大小位置 setTitle("Java窗体的基本操作语句");
    //设置窗体标题 JPanel pnBasic=new JPanel();
    //生成一个大画布 setContentPane(pnBasic);
    //放在窗体中 pnBasic.setLayout(new GridLayout(4,3,5,5));
    //画布按照两行一列网格布局,行与行列与列间隔5像素// JPanel pnGreen=new JPanel();
    //再生成一个小绿画布// JPanel pnYellow=new JPanel();
    //再生成一个小黄画布// pnYellow.setBackground(Color.YELLOW);
    //画布设置颜色// pnGreen.setBackground(Color.GREEN);
    //画布设置颜色// pnBasic.add(pnYellow);
    // pnBasic.add(pnGreen);
    for(int i=0;
    i<(4*3);
    i++) {
    JPanel pn=new JPanel();
    //生成多个小画布 Random ran=new Random();
    int red=ran.nextInt(256);
    int yellow=ran.nextInt(256);
    int blue=ran.nextInt(256);
    pn.setBackground(new Color(red,yellow,blue));
    //画布设置随机颜色 pnBasic.add(pn);
    //放入大画布 }
// final JButton btn = new JButton();
    // btn.setText(" ఠൠఠ小破钮 ఠൠఠ");
    // setContentPane(btn);
    // btn.addActionListener(new ActionListener() {
    // @Override // public void actionPerformed(ActionEvent e) {
    // Random ran = new Random();
    // int index = ran.nextInt(101);
    // System.out.println("Hello!" + index);
    // btn.setText("变变变" + index);
    // }
// }
);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //设置关闭窗体时程序停止运行 setVisible(true);
    //设置窗体可见,否则什么都不会显示 }
public static void main(String[] args) {
    new RP_Frame();
}
}

The above is the detailed content of Basic operation statements of Java forms. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn