⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcomboboxtest.java

📁 编程之道--java程序设计入门源代码
💻 JAVA
字号:
/**
 * 组合框的测试
 */
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class JComboBoxTest
{
	public static void main(String[] args)
	{
		JComboxFrame frame = new JComboxFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.show();
	}
}

class JComboxFrame extends JFrame
{
	private static final int WIDTH = 400;
	private static final int HEIGHT = 300;
	private JLabel textLabel;
	private JComboBox combox;
	
	public JComboxFrame()
	{
		setSize(WIDTH, HEIGHT);//设置框架的大小		
		setTitle("组合框测试");//设置框架的标题
		
		Container con = getContentPane();//得到了内容窗格
		
		textLabel = new JLabel("this is the text font.");
		textLabel.setFont(new Font("serif", Font.PLAIN, 16));
		
		Vector selectItem = new Vector();
		selectItem.add("Serif");
		selectItem.add("SansSerif");
		selectItem.add("DialogInput");
		combox = new JComboBox(selectItem);
		
		JPanel comboxPanel = new JPanel();
		comboxPanel.add(combox);
		combox.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					String newFont = (String)combox.getSelectedItem();
					textLabel.setFont(new Font(newFont, Font.PLAIN, 16));
				}
			});
		
		con.add(comboxPanel, BorderLayout.SOUTH);//将组合框控制面板添加到内容窗格中
		con.add(textLabel, BorderLayout.CENTER);//将标签添加到内容窗格中
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -