📄 frame1.java
字号:
package ex09_07;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Frame1 extends JFrame { JPanel contentPane; JLabel jLabel1 = new JLabel(); ButtonGroup buttonGroup1 = new ButtonGroup(); JRadioButton jRadioButton1 = new JRadioButton(); JRadioButton jRadioButton2 = new JRadioButton(); JRadioButton jRadioButton3 = new JRadioButton(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); jLabel1.setText("改变文字大小"); jLabel1.setBounds(new Rectangle(21, 17, 156, 27)); contentPane.setLayout(null); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); jRadioButton1.setFont(new java.awt.Font("Dialog", 0, 14)); jRadioButton1.setText("18"); jRadioButton1.setBounds(new Rectangle(41, 48, 103, 27)); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton1_actionPerformed(e); } }); jRadioButton2.setFont(new java.awt.Font("Dialog", 0, 14)); jRadioButton2.setText("16"); jRadioButton2.setBounds(new Rectangle(41, 77, 103, 27)); jRadioButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton2_actionPerformed(e); } }); jRadioButton3.setFont(new java.awt.Font("Dialog", 0, 14)); jRadioButton3.setText("12"); jRadioButton3.setBounds(new Rectangle(41, 105, 103, 27)); jRadioButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jRadioButton3_actionPerformed(e); } }); contentPane.add(jLabel1, null); contentPane.add(jRadioButton1, null); contentPane.add(jRadioButton2, null); contentPane.add(jRadioButton3, null); buttonGroup1.add(jRadioButton1); buttonGroup1.add(jRadioButton2); buttonGroup1.add(jRadioButton3); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void jRadioButton1_actionPerformed(ActionEvent e) {//设置字体大小为18jLabel1.setFont(new Font("Dialog",0,18)); } void jRadioButton2_actionPerformed(ActionEvent e) {//设置字体大小为16jLabel1.setFont(new Font("Dialog",0,16)); } void jRadioButton3_actionPerformed(ActionEvent e) {//设置字体大小为12jLabel1.setFont(new Font("Dialog",0,12)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -