求java 200行以上的原创的源代码
发布网友
发布时间:2022-04-23 09:04
我来回答
共2个回答
热心网友
时间:2023-10-09 00:45
import java.awt.*;
import java.awt.event.*;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JFileChooser; import java.awt.*;
import java.awt.event.*;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JFileChooser;
public class TextEditor extends Frame implements ActionListener{
MenuBar mainmenubar=new MenuBar();
Menu file;
MenuItem nw;
MenuItem op;
MenuItem cl;
MenuItem sf;
MenuItem ex;
TextArea tx;
public TextEditor(String title){
super(title);
CloseHandler handler= new CloseHandler();
this.addWindowListener(handler);
setSize(400,400);
setLocationRelativeTo(null);
menuinit();
tx=new TextArea();
this.add(tx);
setVisible(true);
}
void menuinit(){
mainmenubar =new MenuBar();
file=new Menu("File");
nw=new MenuItem("Great");
op=new MenuItem("Open");
cl=new MenuItem("Close");
sf=new MenuItem("save");
ex=new MenuItem("Exit");
file.add(nw);
file.add(op);
file.add(cl);
file.add(sf);
file.add(ex);
mainmenubar.add(file);
setMenuBar(mainmenubar);
nw.addActionListener(this);
op.addActionListener(this);
cl.addActionListener(this);
sf.addActionListener(this);
ex.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Object ob=e.getSource();
JFileChooser f =new JFileChooser();
if((ob==nw)||(ob==ex)){
tx.setText("write word in here");
}else if(ob==op){
f.showOpenDialog(this);
try{
StringBuffer s=new StringBuffer();
FileReader in=new FileReader(f.getSelectedFile());
while(true){
int b=in.read();
if(b==-1)
break;
s.append((char)b);
}
String myString=s.toString();
char[] mychar=myString.toCharArray();
String unkeyFile =FileEncry(mychar);
tx.setText(unkeyFile.toString());
in.close();
}catch(Exception ee){
}
}else if(ob==sf){
f.showSaveDialog(this);
try{
FileWriter out =new FileWriter(f.getSelectedFile());
String mystr=tx.getText();
char[] strchar=mystr.toCharArray();
String keyFile =FileEncry(strchar);
out.write(keyFile);
out.close();
}catch (Exception ee){
}
}else if(ob==ex)
System.exit(0);
}
public static void main(String[] args){
new TextEditor("Simple TextEdit");
}
public String FileEncry(char[] encry){
StringBuffer str=new StringBuffer();
char[] encry1 =new char[encry.length];
for(int i=0; i<encry.length;i++){
encry1[i]=(char) (encry[i]^'F');
str.append(encry1[i]);
}
return str.toString();
}
}
class CloseHandler extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
热心网友
时间:2023-10-09 00:46
能说的再具体点吗?追问因为网上有很多java代码,所以想写个原创的 但苦于没有好的创意 有好的创意也行