📄 liuyang1.java
字号:
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Vector;
import java.io.*;
public class y2
{
public static void main(String args[])
{
jiemian j= new jiemian();
}
}
class jiemian extends Frame implements ActionListener
{
Button b1,b2,b3;
TextArea t1;
TextArea t2;
Label l1,l2,l3;
Color c1=new Color(210,125,165);
public jiemian()
{
super("程序文本处理 作者 刘志刚");
b1= new Button("保留字");
b1.setBounds(150,200,80,20);
b1.addActionListener(this);
b2=new Button("注释字母");
b2.setBounds(250,200,80,20);
b2.addActionListener(this);
b3=new Button("打开文件");
b3.setBounds(50,200,80,20);
b3.addActionListener(this);
l1=new Label("请输入:");
l1.setBounds(40,80,80,40);
l2=new Label("要转换成大写的是:");
l2.setBounds(40,180,100,20);
l3=new Label("结果是:");
l3.setBounds(40,320,100,20);
t1=new TextArea();
t1.setBounds(140,80,190,40);
t2=new TextArea();
t2.setBounds(140,300,190,100);
this.add(b1);
this.add(b2);
this.add(l1);
this.add(b3);
this.add(l2);
this.add(l3);
this.add(t1);
this.add(t2);
this.setLayout(null);
this.setBackground(c1);
this.setSize (400,400);
this.setVisible(true);
this.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{System.exit(0);}
}
);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
boolean bo1=true;
String s1=this.t1.getText();
StringTokenizer zhizhen=new StringTokenizer(s1," ,;()");
Vector v1=new Vector();
//Vector v2=new Vector();
String[] ss1={"auto","break","case","char","const","continue","default","do","double",
"else","enum","extern","float","for","goto","if","int","long","register","return",
"short","signed","sizeof","static","struct","switch","typedef","union","unsigned",
"void","volatile","while"};
int i,k,h;
for(k=0;k<32;k++)
{
v1.add(ss1[k]);
}
h=zhizhen.countTokens();
while(h>0)
{ String s2=zhizhen.nextToken();
String s3=s2;
System.out.println(s2);
bo1=v1.contains(s2);
h--;
if(bo1)
{
s2=s2.toUpperCase();
s1=s1.replaceAll(s3,s2);
}
}
this.t2.setText(s1+"\n");
}
if(e.getSource()==b2)
{//boolean bo2=true;
String s4=this.t1.getText();
int a,b;
a=s4.indexOf("/*");
b=s4.indexOf("*/");
if(a>=0||b>0)
{String s5=s4.substring(a+2,b);
String s6=s5;
s5=s5.toUpperCase();
s4=s4.replaceAll(s6,s5);
this.t2.setText(s4);
}
else{this.t2.setText(s4);
}
}
if(e.getSource()==b3)
{
int b;
byte buffer[]=new byte[2500];
try
{
FileInputStream readfile=new FileInputStream("d:\\example1.c");
b=readfile.read(buffer,0,2500);
try
{
String str=new String(buffer,0,b,"Default");
t1.setText(str);
}
catch(UnsupportedEncodingException ey)
{
t1.setText("the encoding was not found:"+ey);
}
}
catch(IOException ey)
{
t1.setText("file read error");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -