📄 stockframe.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.lang.String.*;
import java.util.*;
public class StockFrame extends Frame implements ActionListener
{
String strLabel1B=" Welcome to Stock Custody System";
String strLabel2B=" Please Input ";
String strLabel3B=" Stock Price ";
String strLabel4B=" Number of Exchange";
String strButton1B="ENTER";
String strLabel1,strLabel2,strLabel3,strLabel4,strButton1;
Label label1;
Label label2;
Label label3;
Label label4;
Button button1;
private TextField textfield1=new TextField(10);
private TextField textfield2=new TextField(10);
private boolean laidOut=false;
RandomAccessFile dataFile;
String readStr="";
Image img;
public StockFrame()
{
try
{
strLabel1=new String(strLabel1B.getBytes("GB2312"),"GB2312");
strLabel2=new String(strLabel2B.getBytes("GB2312"),"GB2312");
strLabel3=new String(strLabel3B.getBytes("GB2312"),"GB2312");
strLabel4=new String(strLabel4B.getBytes("GB2312"),"GB2312");
strButton1=new String(strButton1B.getBytes("GB2312"),"GB2312");
}
catch(Exception e)
{
}
label1=new Label(strLabel1);
label2=new Label(strLabel2);
label3=new Label(strLabel3);
label4=new Label(strLabel4);
button1=new Button(strButton1);
setLayout(null);
add(label1);
add(label2);
add(label3);
add(label4);
add(textfield1);
add(textfield2);
add(button1);
button1.addActionListener(this);
addWindowListener(new closeWin());
setTitle("Stock Custody System PDA Frame");
setSize(240,320);
setVisible(true);
img=getToolkit().getImage("e:\\leap\\src\\examples\\stock.jpg");
setSize(240,320);
}
public void paint(Graphics g)
{
if(!laidOut)
{
Insets insets=insets();
label1.reshape(20+insets.left,30+insets.top,195,20);
label2.reshape(60+insets.right,90+insets.top,100,20);
label3.reshape(25+insets.left,130+insets.top,120,20);
textfield1.reshape(160+insets.right,130+insets.top,50,20);
label4.reshape(25+insets.left,180+insets.top,120,20);
textfield2.reshape(160+insets.right,180+insets.top,50,20);
button1.reshape(90+insets.right,250+insets.bottom,50,20);
laidOut=true;
}
g.drawImage(img,5,20,this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
dataFile = new RandomAccessFile("XXX.txt","rw");
if(ae.getSource()==button1)
{
dataFile.writeBytes(textfield1.getText()+","+textfield2.getText()+" ");
}
}
catch(Exception ie)
{
}
displayData();
}
public void displayData()
{
long fileSize=-1;
byte buffer[]=null;
try
{
RandomAccessFile readFile = new RandomAccessFile("XXX.txt","r");
fileSize = readFile.length();
buffer = new byte[(int)fileSize];
readFile.readFully(buffer,0,(int)fileSize);
readFile.close();
}
catch(Exception oe)
{
System.out.println("can't find XXX.txt ");
}
String tempStr = new String(buffer, 0,(int)fileSize);
StringTokenizer st = new StringTokenizer(tempStr.trim(),",");
while(st.hasMoreTokens())
{
System.out.println(st.nextToken());
}
}
public static void main(String[] args)
{
StockFrame s=new StockFrame();
s.setVisible(true);
}
}
class closeWin extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
Frame frame=(Frame)(we.getSource());
frame.dispose();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -