?? mainframe.java
字號:
import java.awt.BorderLayout;
import com.keypoint.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import java.io.*;
import java.awt.Rectangle;
import java.awt.Font;
import javax.imageio.ImageIO;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class MainFrame extends JFrame {
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JTextField ztext = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField xtext = new JTextField();
JTextField ytext = new JTextField();
JButton jButton1 = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
String message;
String timeStr;
Image clockImage = null;
int hour, minute;
boolean encodeAlpha = false;
int filter = 0;
int compressionLevel = 1;
int pixelDepth = 24;
String filename;
boolean fileSaved = false;
String filepath="d:\\haha",fn="cyvcy.txt",line=null;
File file=null,fimg=null;
FileReader fw=null;
BufferedReader br=null;
int l=0,m,m0,n=0;
int x=20,y=20,z=20,w=3000,h=250;
char[] b=null;
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel4 = new JLabel();
JTextField width = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField height = new JTextField();
JButton jButton2 = new JButton();
Image img=null;
public MainFrame() {
try {
this.setTitle("七星彩走勢圖生成器");
this.setSize(new Dimension(300, 260));
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
fimg= new File("images","title.png");
img=ImageIO.read(fimg);
this.setIconImage(img);
getContentPane().setLayout(borderLayout1);
jButton1.addActionListener(new MainFrame_jButton1_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(180, 20, 95, 190));
//jTextArea1.setBounds(new Rectangle(180, 20, 86, 190));
ztext.setBounds(new Rectangle(90, 20, 77, 20));
jLabel1.setBounds(new Rectangle(56, 23, 27, 15));
xtext.setBounds(new Rectangle(90, 53, 77, 20));
ytext.setBounds(new Rectangle(90, 86, 77, 20));
jLabel2.setBounds(new Rectangle(20, 57, 63, 15));
jLabel3.setBounds(new Rectangle(21, 89, 62, 15));
jLabel4.setText("圖片寬");
jLabel4.setBounds(new Rectangle(43, 122, 40, 15));
width.setBounds(new Rectangle(90, 120, 77, 20));
jLabel5.setText("圖片高");
jLabel5.setBounds(new Rectangle(43, 156, 42, 15));
height.setBounds(new Rectangle(90, 153, 77, 20));
jButton1.setBounds(new Rectangle(20, 188, 82, 23));
jButton2.setBounds(new Rectangle(111, 188, 56, 23));
jButton2.setText("查看");
jButton2.addActionListener(new MainFrame_jButton2_actionAdapter(this));
this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel1.setLayout(null);
jLabel1.setText("邊距");
jLabel2.setText("橫坐標間距");
jLabel3.setText("縱坐標間距");
jButton1.setText("生成圖片");
ztext.setText(String.valueOf(z));
xtext.setText(String.valueOf(x));
ytext.setText(String.valueOf(y));
width.setText(String.valueOf(w));
height.setText(String.valueOf(h));
jScrollPane1.getViewport().add(jTextArea1);
jPanel1.add(ztext);
jPanel1.add(jLabel1);
jPanel1.add(jLabel2);
jPanel1.add(xtext);
jPanel1.add(ytext);
jPanel1.add(jLabel3);
jPanel1.add(jButton1);
jPanel1.add(jButton2);
jPanel1.add(jLabel4);
jPanel1.add(width);
jPanel1.add(height);
jPanel1.add(jLabel5);
jPanel1.add(jScrollPane1);
file=new File(fn);
this.setBackground(Color.WHITE);
this.setResizable(false);
}
public void drawClockImage(int hour, int minute,int wei)
{
this.n=wei;
Graphics g;
Font smallFont = new Font("Helvetica", Font.PLAIN, 9 );
g = clockImage.getGraphics();
g.setXORMode(Color.white);
//g.setColor(Color.white);
g.setFont( smallFont );
try{
g.drawLine(z,0,z,y*10+z);
int i=0;
Color c=new Color(251,222,222);
for(int j=9;j>-1;j--){
g.drawString(String.valueOf(j),5,(9-j)*y+z);
g.setColor(c);
g.drawLine(z,(9-j)*y+z,w,(9-j)*y+z);
g.setColor(Color.BLACK);
}
try{
fw=new FileReader(file);
br=new BufferedReader(fw);
while((line=br.readLine())!=null){
g.setColor(Color.BLACK);
if(i!=0)
m0=m;
l=line.indexOf("=");
if(l!=0)
line=line.substring(l+1);
if(!line.equals("")){
if(line.length()>=n+1)
m=Integer.parseInt(line.substring(n,n+1));
else
continue;
}
//break;
if(i!=0){
if(w>=(i * x + z)){
g.setColor(Color.RED);
g.drawLine((i - 1) * x + z, (9 - m0) * y + z,
i * x + z,
(9 - m) * y + z);
g.setColor(c);
g.drawLine(i * x + z, z, i * x + z, y * 10 + z);
}else
break;
}
i++;
}
System.out.println(i);
br.close();
fw.close();
}catch(Exception ex){}
g.drawLine(0,y*10+z,x*i+z,y*10+z);
}catch(Exception e){}
Font hFont = new Font("宋體", Font.PLAIN, 12 );
g.setFont( hFont );
g.drawString("第"+(n+1)+"位",5,240);
}
public void saveClockImage()
{
byte[] pngbytes;
PngEncoder png = new PngEncoder( clockImage,
(encodeAlpha) ? PngEncoder.ENCODE_ALPHA : PngEncoder.NO_ALPHA,
filter, compressionLevel);
try
{
FileOutputStream outfile = new FileOutputStream( filename );
pngbytes = png.pngEncode();
if (pngbytes == null)
{
jTextArea1.setText(jTextArea1.getText()+"Null image!\n");
}
else
{
outfile.write( pngbytes );
}
outfile.flush();
outfile.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
//Help | About action performed
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public void jButton1_actionPerformed(ActionEvent e) {
this.x=Integer.parseInt(xtext.getText());
this.y=Integer.parseInt(ytext.getText());
this.z=Integer.parseInt(ztext.getText());
this.w=Integer.parseInt(width.getText());
this.h=Integer.parseInt(height.getText());
for(int i=0;i<7;i++){
if (clockImage == null) {
clockImage = createImage(w, h);
}
if (clockImage != null) {
if (!fileSaved) {
drawClockImage(hour, minute, i);
filename = "img\\" + (i+1) + ".png";
saveClockImage();
fileSaved = true;
}
jTextArea1.setText(jTextArea1.getText()+"成功:" + filename+"\n");
} else
jTextArea1.setText(jTextArea1.getText()+"失敗:" + filename+"\n");
fileSaved = false;
clockImage=null;
}
}
public void jButton2_actionPerformed(ActionEvent e) {
ImgView iv=new ImgView();
//Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//iv.setSize(screenSize.width,screenSize.height);
}
}
class MainFrame_jButton2_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jButton2_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class MainFrame_jButton1_actionAdapter implements ActionListener {
private MainFrame adaptee;
MainFrame_jButton1_actionAdapter(MainFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -