怎么使textArea怎么实现combobox里面的Item事件
还有别的JRadioButton啊什么的,怎么写事件才能让多行文本框实现这些事件这是代码 监听事件写不来
package com.great.nf1108.demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LayoutExciseFrame extends JFrame {
JLabel labFace = new JLabel("字体");
JLabel labSize = new JLabel("大小");
JComboBox comboBoxFace = new JComboBox();
JComboBox comboBoxSize = new JComboBox();
JRadioButton checkBoxBold = new JRadioButton("粗体");
JRadioButton checkBoxItalic = new JRadioButton("斜体");
JTextArea txtArea = new JTextArea("这里是设置字体的预览区,示例文字");
ButtonGroup spRadioButton = new ButtonGroup();
public LayoutExciseFrame() {
setTitle("设置字体");
setSize(500, 400);
initComponent();
initLayout();
setMenu();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* 初始化布局
*/
private void initLayout() {
JPanel panelLeft = new JPanel();// 左侧布局面板
JPanel panelTop = new JPanel();// 顶部布局面板
JPanel panelBottom = new JPanel();// 底部布局面板
JPanel panelFace = new JPanel();// 放置字体设置相关控件的 面板
JPanel panelSize = new JPanel();// 放置大小设置相关控件的 面板
panelFace.setLayout(new FlowLayout(FlowLayout.LEFT));
panelFace.add(labFace);
spRadioButton.add(checkBoxBold);
spRadioButton.add(checkBoxItalic);
panelFace.add(comboBoxFace);
panelSize.setLayout(new FlowLayout(FlowLayout.LEFT));
panelSize.add(labSize);
panelSize.add(comboBoxSize);
panelTop.setLayout(new GridLayout(2, 1));
panelTop.add(panelFace);
panelTop.add(panelSize);
panelBottom.setLayout(new GridLayout(6, 1));
panelBottom.add(new JPanel());
panelBottom.add(new JPanel());
JPanel panelBold = new JPanel();
panelBold.add(checkBoxBold);
JPanel panelItatic = new JPanel();
panelItatic.add(checkBoxItalic);
panelBottom.add(panelBold);
panelBottom.add(panelItatic);
panelBottom.add(new JPanel());
panelBottom.add(new JPanel());
panelLeft.setLayout(new BorderLayout());
panelLeft.add(panelTop, BorderLayout.NORTH);
panelLeft.add(panelBottom);
add(panelLeft, BorderLayout.WEST);
add(txtArea);
}
/**
* 初始化组件
*/
public void initComponent() {
comboBoxFace.addItem("宋体");
comboBoxFace.addItem("楷体-GB2312");
comboBoxSize.addItem(12);
comboBoxSize.addItem(14);
comboBoxSize.addItem(24);
}
/**
* 设置菜单
*/
private void setMenu() {
MenuBar menuBar = new MenuBar();
Menu menuColor = new Menu("字体颜色");
MenuItem menuItemRed = new MenuItem("红色");
MenuItem menuItemBlue = new MenuItem("蓝色");
MenuItem menuItemGreen = new MenuItem("绿色");
// 把菜单项放入菜单
menuColor.add(menuItemRed);
menuColor.add(menuItemGreen);
menuColor.add(menuItemBlue);
// 将菜单加入到菜单条中
menuBar.add(menuColor);
setMenuBar(menuBar);// 设置菜单条到当前窗口中
}
}