?? word.java
字號:
package test.paint;
import java.awt.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
/**
* Word類,實現文字的大小,風格,類型功能
* 作者:鐘雯
* 初始時間:2007 5-12
* 最后一次修改時間:2007 5-29
*/
public class Word extends RectBoundedShape {
//字體風格
int temp1, temp2;
//字體大小
int temp4 ;
//字體類型
String temp3 ;
//輸入內容
String input ;
/**
* 有參構造函數,通過參數傳遞獲取有關字體大小,類型以及風格的信息
*/
public Word(Color c, Stroke s, int x, int y, int d, int e, int h, String f ) {
super(c, s, x, y);
temp1 = d ;
temp2 = e ;
temp3 = f ;
temp4 = h ;
input = JOptionPane.showInputDialog("輸入文本:");
}
/**
* 無參構造函數
*/
public Word() {
super();
}
/**
* Draw method
*/
public void draw(Graphics2D g)
{
g.setColor(color);
g.setStroke(stroke);
//設置字體類型,風格,大小
g.setFont(new Font(temp3, temp1+temp2, temp4*2));
if(input!=null)
g.drawString(input, super.startX, super.startY);
}
/**
* 獲得文字的相關信息,暫時存放到StringBuffer變量中,當保存文件時調用該函數
*/
public String getShapeData() {
int si = 0;
for (int i=0; i<MyPanel.STROKES.length; i++) {
if (stroke == MyPanel.STROKES[i]) {
si = i;
break;
}
}
StringBuffer buffer = new StringBuffer();
buffer.append(color.getRGB());
buffer.append(":");
buffer.append(si);
buffer.append(":");
buffer.append(startX);
buffer.append(":");
buffer.append(startY);
buffer.append(":");
buffer.append(endX);
buffer.append(":");
buffer.append(endY);
buffer.append( ":" );
buffer.append( model );
buffer.append( ":" );
buffer.append(input);
buffer.append(":");
buffer.append(temp3);
buffer.append(":");
buffer.append(temp1);
buffer.append(":");
buffer.append(temp2);
buffer.append(":");
buffer.append(temp4*4);
buffer.append(":");
return buffer.toString();
}
/**
* 當打開文件時,調用該函數,設置文字的相關信息
*/
public void setShapeData(String data) throws Exception {
String[] splits = data.split(":");
color = new Color(Integer.parseInt(splits[0]));
stroke = MyPanel.STROKES[Integer.parseInt(splits[1])];
startX = Integer.parseInt(splits[2]);
startY = Integer.parseInt(splits[3]);
endX = Integer.parseInt(splits[4]);
endY = Integer.parseInt(splits[5]);
model = Integer.parseInt( splits[6] );
input = String.valueOf(splits[7]);
temp3 = String.valueOf(splits[8]);
temp1=Integer.parseInt(splits[9]);
temp2=Integer.parseInt(splits[10]);
temp4=Integer.parseInt( splits[11] )/4;
}
public Rectangle getBounds() {
// TODO Auto-generated method stub
return null;
}
public boolean isImage() {
// TODO Auto-generated method stub
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -