怎么使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);// 设置菜单条到当前窗口中
}
}
搜索更多相关的解决方案:
check
----------------解决方案--------------------------------------------------------
程序代码:
public void actionPerformed(ActionEvent e) {
sT=(String) jbx.getSelectedItem();//
ss= (String) jbx2.getSelectedItem();
is=Integer.valueOf(ss);
sty=0;
switch (jbx3.getSelectedIndex()) {
case 1:
sty=Font.BOLD;
break;
case 2:
sty=Font.ITALIC;
break;
case 3:
sty=Font.PLAIN;
break;
}
font=new Font(sT,sty,is);
switch (jbx1.getSelectedIndex()) {
case 0:
clr=Color.WHITE;
break;
case 1:
clr=Color.CYAN;
break;
case 2:
clr=Color.ORANGE;
break;
case 3:
clr=Color.BLACK;
break;
case 4:
clr=Color.RED;
break;
case 5:
clr=Color.YELLOW;
break;
case 6:
clr=Color.GRAY;
break;
case 7:
clr=Color.BLUE;
break;
case 8:
clr=Color.GREEN;
break;
case 9:
clr=Color.GREEN;
break;
}
setFt(font,clr);
dispose();
}
void setFt(Font font,Color clr){sT=(String) jbx.getSelectedItem();//
ss= (String) jbx2.getSelectedItem();
is=Integer.valueOf(ss);
sty=0;
switch (jbx3.getSelectedIndex()) {
case 1:
sty=Font.BOLD;
break;
case 2:
sty=Font.ITALIC;
break;
case 3:
sty=Font.PLAIN;
break;
}
font=new Font(sT,sty,is);
switch (jbx1.getSelectedIndex()) {
case 0:
clr=Color.WHITE;
break;
case 1:
clr=Color.CYAN;
break;
case 2:
clr=Color.ORANGE;
break;
case 3:
clr=Color.BLACK;
break;
case 4:
clr=Color.RED;
break;
case 5:
clr=Color.YELLOW;
break;
case 6:
clr=Color.GRAY;
break;
case 7:
clr=Color.BLUE;
break;
case 8:
clr=Color.GREEN;
break;
case 9:
clr=Color.GREEN;
break;
}
setFt(font,clr);
dispose();
}
文本域.setFont(font);
文本域.setForeground(clr);
}
我这是以前做的 用一个按钮来提交事件
----------------解决方案--------------------------------------------------------