JFrame frame = new JFrame(Button Example); JButton button = new JButton(Click Me); button.setBounds(100, 100, 100, 50); frame.add(button); frame.setSize(300, 200); frame.setLayout(null); frame.setVisible(true);
import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JFrame; public class JPanelExample { public static void main(String[] args) { JFrame frame = new JFrame("JPanel Example"); frame.setSize(400, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pa...
// Java 示例代码importjavax.swing.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;publicclassButtonClickExample{publicstaticvoidmain(String[]args){JFrameframe=newJFrame("按钮点击事件示例");JButtonbutton=newJButton("点击我");button.addActionListener(newActionListener(){@Override...
300);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JPanel panel=newJPanel();JButton button=newJButton("Click me!");panel.add(button);frame.getContentPane().add(panel);frame.
javax.swing.JButton 1.2 • JButton(String label) 构造一个按钮。标签可以是常规的文本,从JDK 1.3开始,也可以是HTML。例如,"<html><b>Ok</b></html>"。 参数:label 显示在按钮表面的文本 • JButton(Icon icon) 构造一个按钮。 参数:icon 显示在按钮表面的图标 ...
CloseOperation(JFrame.EXIT_ON_CLOSE);6667jf.setVisible(true);68}6970privatestaticvoidtestBox() {71JFrame jf =newJFrame("用户登录");72jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);7374//第 1 个 JPanel, 使用默认的浮动布局75JPanel panel01 =newJPanel();76panel01.add(newJLabel(...
JFrame frame = new JFrame("小龙按钮"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 创建一个面板 JButtonExample3 newContentPane = new JButtonExample3(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane);
button=new JButton("点击我,出现新窗体");add(button);button.addActionListener(this);this.setLayout(new FlowLayout());this.setBounds(520, 130, 200, 100);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);} public static void main(String args[]){ formshow...
在Java中使用Swing来编写一个答题器的图形界面,可以通过手动编写代码或者使用Eclipse等IDE中的UI设计插件来拖拽组件设计界面。以下是两种方法的简要步骤:方法一:手动编写代码创建主框架:使用JFrame类创建一个主窗口。设置窗口的标题、大小和关闭操作。添加组件:使用JPanel、JLabel、JTextField、JButton等...
button.addActionListener(newActionListener() { @OverridepublicvoidactionPerformed(ActionEvent e) { System.out.println("click JB"); } });//去掉按钮文字周围的焦点框button.setFocusPainted(false); jframe.getContentPane().add(button); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ...