JFrame2

复制代码
package com.fxb.gui;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout.Alignment;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.UIManager;

public class Test2_JFrame extends JFrame{
    
    JButton button1 = new JButton("Button1");
    JButton button2 = new JButton("Button2");
    JButton button3 = new JButton("Button3");
    TextField field = new TextField(10);
    JComboBox comboBox = new JComboBox();    
    JCheckBox checkBox = new JCheckBox("Check1");
    JRadioButton radioButton1 = new JRadioButton("Radio1");
    JRadioButton radioButton2 = new JRadioButton("Radio1");
    
    ButtonGroup buttonGroup = new ButtonGroup();
    
    public Test2_JFrame(){
//        try{
////            UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName( ) );
////            UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
////            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel" );
//        }catch(Exception e){
//            e.printStackTrace();
//        }

            
        setVisible(true);
        setLayout(new FlowLayout(FlowLayout.LEFT ));
//        setLayout(new FlowLayout(FlowLayout.CENTER ));
        setSize(300, 300);
        setAutoRequestFocus(false);
        setResizable(false);
        
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 2, 10, 5));
        panel.setSize(200, 200);
        add(panel);
        
        panel.add(button1);
        panel.add(button2);
        panel.add(button3);
        //panel.add(field);
        
        comboBox.addItem("Item1");
        comboBox.addItem("Item2");
        comboBox.addItem("Item3");
        panel.add(comboBox);
        
        panel.add(checkBox);
        buttonGroup.add(radioButton1);
        buttonGroup.add(radioButton2);
        panel.add(radioButton1);
        panel.add(radioButton2);
        
        JTextArea textArea = new JTextArea();
        textArea.setSize(100, 100);
        add(textArea);
        
//        add(button1);
//        add(button2);
//        add(button3);
        
        button1.addActionListener(actionListener);
        button2.addActionListener(actionListener);
        button3.addActionListener(actionListener);
    }
    
    private ActionListener actionListener = new ActionListener(){
        public void actionPerformed(ActionEvent e) {
            if(e.getSource() == button1){
                pt("button1");
            }else if(e.getSource() == button2){
                pt("button2");
            }else if(e.getSource() == button3){
                pt("button3");
            }
        }
    };
    

    
    private static StringBuilder builder = new StringBuilder();
    public static void pt(Object a){
        builder.setLength(0);
        builder.append(a);
        System.out.println(builder.toString());
    }
    
    public static void main(String[] args){
        new Test2_JFrame();
    }

}
复制代码

posted @   丛林小阁楼  阅读(253)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示