📄 jtest.java
字号:
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.Container;
import javax.swing.JFrame;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.JScrollPane;
public class Jtest extends JFrame {
JButton b1;
JButton b2;
JTextArea ta;
JScrollPane sp;
public Jtest()
{
super("测试程序");
b1=new JButton("读取数据");
b2=new JButton("写入数据");
ta=new JTextArea(5,8);
sp=new JScrollPane(ta);
Container c=getContentPane();
c.setLayout(new FlowLayout());
c.add(b1);
c.add(b2);
c.add(sp);
b1.addActionListener(new ActionListener()
{
Scanner in=new Scanner(System.in);
String name=in.nextLine();
public void actionPerformed(ActionEvent e)
{
int temp;
int count=0;
try{
DataInputStream f=new DataInputStream(new FileInputStream(name));
temp=f.readInt();
while(count<10)
{
ta.setText(String.valueOf(temp));
count++;
}
}catch(IOException e1)
{
e1.printStackTrace();
}
}
}
);
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String s=ta.getText();
try{
DataOutputStream f=new DataOutputStream(new FileOutputStream("out.txt",true));
f.writeBytes(s);
}catch(IOException e1)
{
e1.printStackTrace();
}
}
}
);
}
public static void main(String args[])
{
Jtest test=new Jtest();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
test.setSize(300, 200);
test.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -