文本編輯器源文件(java語(yǔ)言) |
|
Chinageren.com 2004-8-25
轉(zhuǎn)載注明:www.  |
/版權(quán)所有helj import java.awt.*; import java.io.*; import java.util.*; //W_color;C_str;C_file;C_back;W_find;W_fond
interface I_Method { public void setQuit(); public void setfont(Font f); public void setcolor(Color c); public void Find(String find,int dire); }
class D_color extends Dialog { private Button OK,Cancel; private I_Method mp; private Rectangle test;
private Color current= Color.black; private Color []colors; private Color []colors1; private Color []colors2; private int strlen= 250;
public D_color(Frame fr,I_Method mp,int x,int y) { super(fr,"調(diào)色板",true); this.mp= mp; colors= new Color[strlen]; colors1= new Color[strlen]; colors2= new Color[strlen]; for (int i = 0; i < strlen; i++) { float h = ((float)i)/((float)strlen); colors[i] = new Color(Color.HSBtoRGB(h,1.0f,1.0f)); } for (int i = 0; i < strlen; i++) { float h = ((float)i)/((float)strlen); colors1[i] = new Color(Color.HSBtoRGB(1.0f,h,1.0f)); } for (int i = 0; i < strlen; i++) { float h = ((float)i)/((float)strlen); colors2[i] = new Color(Color.HSBtoRGB(1.0f,1.0f,h)); } setLayout(null); OK= new Button("確定"); Cancel= new Button("取消"); OK.reshape(320,100,80,30); add(OK); Cancel.reshape(320,150,80,30); add(Cancel); test= new Rectangle(0,0,300,250); reshape(x/2-210,y/2-140,420,280); show(); }
public void update(Graphics g) { int y= 0; for (int i = 0; i < strlen; i++) { g.setColor(colors[i]); g.fillRect(0,y,100,1); y+=1; } y= 0; for (int i = 0; i < strlen; i++) { g.setColor(colors1[i]); g.fillRect(100,y,100,1); y+=1; } y= 0; for (int i = 0; i < strlen; i++) { g.setColor(colors2[i]); g.fillRect(200,y,100,1); y+=1; } g.setColor(current); g.fillRect(330,30,60,60); } public void paint(Graphics g) { update(g); }
public boolean mouseMove(Event evt,int x,int y) { if(test.inside(x,y)) { Graphics g1= getGraphics(); //g1.drawImage(back,oldx,oldy); //g1.clipRect(x-3,y-3,6,6); g1.setColor(Color.white); g1.drawArc(x-3,y-3,6,6,60,360); g1.drawLine(x-3,y,x+3,y); g1.drawLine(x,y-3,x,y+3); repaint(); //oldx= x-3; //oldy= y-3; return true; } return false; }
public boolean mouseDown(Event evt,int x,int y) { if((x>=0)&&(x<=100)) { current= colors[y]; System.out.println(y); getGraphics().setColor(current); getGraphics().fillRect(330,30,60,60); return true; } if((x>100)&&(x<=200)) { current= colors1[y]; getGraphics().setColor(current); getGraphics().fillRect(330,30,60,60); return true; } if((x>200)&&(x<=300)) { current= colors2[y]; getGraphics().setColor(current); getGraphics().fillRect(330,30,60,60); return true; } return false; }
public boolean action(Event evt,Object arg) { if(evt.target instanceof Button) { if(evt.target== OK) { mp.setcolor(current); dispose(); return true; } if(evt.target== Cancel) { dispose(); return true; } } return super.action(evt,arg); } }
class W_quick extends Window { MainF fr; private Dimension sz; private int w,h; private int fw,fh; private FontMetrics fm; private int index=0;
public W_quick(MainF fr,I_Method qm,int x,int y) { super(fr); this.fr= fr; setBackground(Color.lightGray); }
public void show(int x,int y) { repaint(); reshape(x,y,100,160); show(); }
private void draw_uplines(Graphics g,int x,int y,int w1,int h1) { g.setColor(Color.white); g.drawLine(x,y,x+w1-1,x); g.drawLine(x,y,x,y+h1-1);
g.setColor(Color.black); g.drawLine(x+w1-1,y-1,x+w1-1,y+h1-1); g.drawLine(x+w1-2,y+1,x+w1-2,y+h1-2); g.drawLine(x+1,y+h-2,x+w1-2,y+h1-2); // g.drawLine(x,y+h1-1,x+w1-1,y+h1-1); // g.setColor(Color.black); // g.drawLine(x,y+h1-1,x+w1-1,y+h1-1); } public void paint(Graphics g) { sz= size(); w= sz.width; h= sz.height; // g.setFont(Ffont); fm= g.getFontMetrics(); fh=fm.getHeight(); fw= fm.charWidth(‘‘C‘‘); g.setColor(Color.gray); g.drawRect(10,(index-1)*fh+6,w-20,fh); // g.setColor(Color.lightGray); // g.drawRect(0,0,w,h); draw_uplines(g,1,1,w-1,h-1); g.setColor(Color.black); g.drawString("Cut",13,fh); g.drawString("Copy",13,2*fh); g.drawString("Paste",13,3*fh); g.drawString("Delete",13,4*fh); }
public boolean mouseMove(Event evt,int x,int y) { for(int i=1;i<=4;i++) if((y>(i-1)*fh)&&(y<(i*fh))) { index= i; repaint(); } return super.mouseMove(evt,x,y); }
public boolean mouseDown(Event evt,int x,int y) { if(y>0&&y<fh) { fr.current_t.dels(); fr.eitem.enable(false); fr.eitem1.enable(false); fr.eitem3.enable(false); fr.eitem2.enable(true); hide(); return true; } if(y>fh&&(y<(2*fh))) { fr.eitem.enable(false); fr.eitem1.enable(false); fr.eitem3.enable(false); fr.eitem2.enable(true); hide(); return true; } if((y>(2*fh))&&(y<(3*fh))) { fr.current_t.adds(); fr.eitem2.enable(false); fr.eitem.enable(false); fr.eitem1.enable(false); fr.eitem3.enable(false); hide(); return true; } if((y>(3*fh))&&(y<(4*fh))) { fr.current_t.dels(); fr.eitem3.enable(false); fr.eitem.enable(false); fr.eitem1.enable(false); fr.eitem2.enable(false); hide(); return true; } return super.mouseDown(evt,x,y); } }
class ptest extends Panel { String test= "ABCDabcd"; D_font ff;
public ptest(D_font ff) { this.ff= ff; repaint(); }
private void draw_downlines(Graphics g,int x,int y,int w,int h) { g.setColor(Color.white); g.drawLine(x+1,y+h-1,x+w-1,y+h-1); g.drawLine(x+w-1,y+h-1,x+w-1,y+1); g.setColor(Color.black); g.drawLine(x,y,x,y+h); g.drawLine(x+1,y+1,x+1,y+h-1); g.drawLine(x,y,x+w,y); g.drawLine(x+1,y+1,x+w-1,y+1); }
public void rep() { repaint(); } public void paint(Graphics g) { Dimension sz= size(); Point pt= location(); g.setColor(Color.darkGray); g.drawRect(0,0,sz.width-2,sz.height-2);
g.setColor(Color.white); g.drawLine(1,1,1,sz.height-3); g.drawLine(1,1,sz.width-3,1);
g.drawLine(0,sz.height-1,sz.width-1,sz.height-1); g.drawLine(sz.width-1,0,sz.width-1,sz.height-1);
draw_downlines(g,15,10,sz.width-30,sz.height-20); g.clipRect(16,11,sz.width-31,sz.height-21); g.setColor(Color.black); g.setFont(ff.bf); g.drawString(test,20,sz.height-21); } }
class D_font extends Dialog { public Font bf; private Button OK,Cancel; private Label l1,l2,l3; private String items1[]={"Helvetica","Courier","TimesRoman","Dialog"}; private String items2[]={"PLAIN","BOLD","PLAIN+BOLD","ITALIC","BOLD+ITALIC"}; private int[] style= new int[5]; private String items3[]={"8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"}; private TextField f1,f2,f3; private List ll1,ll2,ll3; private ptest test; private I_Method im;
public void init() { style[0]= Font.PLAIN; style[1]= Font.BOLD; style[2]= Font.PLAIN+Font.BOLD
[1] [2] [3] [4] |
|