记事本
来源:互联网 发布:sql 取日期部分 编辑:程序博客网 时间:2024/06/02 20:58
记事本
还没写完,下次再写
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.plaf.ComboBoxUI;
import org.omg.CORBA.Environment;
public class JishiText extends JFrame implements ActionListener{
private JComboBox cboxName,cboxSize;
private JTextArea jtArea;
private JCheckBox jCheck1,jCheck2;
private JRadioButton jRadio[];
public JishiText() {
Dimension dim=getToolkit().getScreenSize();
setBounds(dim.width/4,dim.height/4 , dim.width*4/7, dim.height/2);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//getContentPane().setLayout(new f)
JMenuBar jbar=new JMenuBar();
getContentPane().add(jbar,BorderLayout.NORTH);
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] ZiName=ge.getAvailableFontFamilyNames();
cboxName=new JComboBox(ZiName);
cboxName.addActionListener(this);
String[] ZiSize={"20","30","40","50"};
cboxSize=new JComboBox(ZiSize);
cboxSize.setEditable(true);
jbar.add(cboxName);
jbar.add(cboxSize);
cboxSize.addActionListener(this);
jtArea=new JTextArea("Welcom 欢迎");
getContentPane().add(jtArea);
jCheck1=new JCheckBox("粗体");
jCheck2=new JCheckBox("斜体");
jbar.add(jCheck1);
jbar.add(jCheck2);
jCheck1.addActionListener(this);
jCheck2.addActionListener(this);
//jRadio1=new JRadioButton("红");
//jRadio2=new JRadioButton("蓝");
//jRadio3=new JRadioButton("绿");
String rbColor[]={"红","蓝","绿"};
ButtonGroup bgroup=new ButtonGroup();
jRadio=new JRadioButton[rbColor.length];
for(int i=0;i<rbColor.length;i++){
jRadio[i]=new JRadioButton(rbColor[i]);
bgroup.add(jRadio[i]);
jbar.add(jRadio[i]);
jRadio[i].addActionListener(this);
}
setVisible(true);
}
public static void main(String[] args) {
new JishiText();
}
boolean isFirst=false;
@Override
public void actionPerformed(ActionEvent e) {
// boolean isFirst=false;
if(isFirst==true && e.getSource()==cboxSize){
isFirst=false;
return;
}
if(e.getSource()instanceof JComboBox||e.getSource()instanceof JCheckBox){
String strSize="";
try {
String strFontName=(String) cboxName.getSelectedItem();
strSize=(String) cboxSize.getSelectedItem();
int size=Integer.parseInt(strSize);
if(size<4||size>120){
throw new NumberFormatException();
}
Font font=jtArea.getFont();
int style =font.getStyle();
if(e.getSource()==jCheck1){
style=style ^1;
}
if(e.getSource()==jCheck2){
style=style ^2;
}
jtArea.setFont(new Font(strFontName, style, size));
} catch (NumberFormatException e1) {
JOptionPane.showMessageDialog(this, "字体格式错误,请从新输入");
isFirst=true;
}
}
if(e.getSource()instanceof JRadioButton){
Color c=null;
if(e.getSource()==jRadio[0]){
c=new Color(255,0,0);
}
if(e.getSource()==jRadio[1]){
c=new Color(0,0,255);
}
if(e.getSource()==jRadio[2]){
c=new Color(0,255,0);
}
jtArea.setForeground(c);
}
}
}
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- 记事本
- C++第五次作业
- Mark Git 初步
- 常用bat批处理命令
- URI、URL与URN的区别
- xml解析-pull和dom4j
- 记事本
- java线程同步:synchronized
- DES算法原理C++模拟实现
- 文字检测与识别4-过分割和beam search
- 我的第一篇博客
- synchronized 与 ReentrantLock 同步代码块简单实现
- 使用More like this实现基于内容的推荐
- fedora23 安装smplayer
- Codeblocks的主题设置