⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 word.java

📁 Java画板
💻 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 + -