java文本编辑器v2.0 图形用户界面(二)

2014-11-23 21:43:50 · 作者: · 浏览: 25
((String)combox_size.getSelectedItem()); Font font = ta.getFont(); //获得文本区的当前字体对象 int style = font.getStyle(); //获得字形 ta.setFont(new Font(fontname, style, size)); } }); ////////////////////字号加减按钮 button_larger=new JButton("A+"); toolbar.add(button_larger); button_larger.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String fontname = (String)combox_name.getSelectedItem();//获得字体名 Font font = ta.getFont(); //获得文本区的当前字体对象 int style = font.getStyle(); //获得字形 int size = font.getSize()+5; ta.setFont(new Font(fontname, style, size)); } }); button_smaller=new JButton("A-"); toolbar.add(button_smaller); button_smaller.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String fontname = (String)combox_name.getSelectedItem();//获得字体名 Font font = ta.getFont(); //获得文本区的当前字体对象 int style = font.getStyle(); //获得字形 int size = font.getSize()-5; ta.setFont(new Font(fontname, style, size)); } }); /////////////////J /////////////////粗体和斜体 checkb_bold = new JCheckBox("粗体"); //字形复选框 toolbar.add(checkb_bold); checkb_bold.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String fontname = (String)combox_name.getSelectedItem();//获得字体名 Font font = ta.getFont(); //获得文本区的当前字体对象 int style = font.getStyle(); //获得字形 int size = font.getSize(); style = style ^ 1; ta.setFont(new Font(fontname, style, size)); } }); checkb_italic = new JCheckBox("斜体"); toolbar.add(checkb_italic); checkb_italic.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String fontname = (String)combox_name.getSelectedItem();//获得字体名 Font font = ta.getFont(); //获得文本区的当前字体对象 int style = font.getStyle(); //获得字形 int size = font.getSize(); style = style ^ 2; ta.setFont(new Font(fontname, style, size)); } }); //////////////// JRadioButton radiob_color[]; String colorstr[]={"红","绿","蓝"}; ButtonGroup bgroup_color = new ButtonGroup(); //按钮组 radiob_color = new JRadioButton[colorstr.length]; //颜色单选按钮数组 for (int i=0; i

\

\

\

\