16 22小试身手 import java. awt. * import java util. Date; public class show Date extends java applet Applet i Date timeNow=new Date; String title, Font msg Font-new Font(“ Timesroman”, Font. ITALIC,30) public void paint(Graphics g) public void initO ig setFont(msg Font) ititle=getParameter gset Color(Color blue); (“rem”); g. darwString (title+ if(title==null timeNow toString(, 5, 50); title=4”;
16 2.2 小试身手 import java.awt.*; import java.util.Date; public class showDate extends java.applet.Applet { Date timeNow=new Date(); String title; Font msgFont=new Font(“TimesRoman”,Font.ITALIC,30); public void init() {title=getParameter (“rem”); if (title==null) title=“”; } public void paint(Graphics g) { g.setFont(msgFont); g.setColor(Color.blue); g.darwString(title+ timeNow.toString(),5,50); }
22小试身手 例:利用一个可以显示运行字符串的类,显示自 己的字符串( htmlpara. htm) <applet code=htmlpara class width=300 heigh=200> param name=MESSAGE value=this is a test param name=FONT value= BOLD> <param name=POINT SIZE value=20></applets
17 2.2 小试身手 • 例:利用一个可以显示运行字符串的类,显示自 己的字符串 (htmlpara.html) <applet code=htmlpara.class width=300 heigh=200> <param name=MESSAGE value=”this is a test"> <param name=FONT value="BOLD"> <param name=POINT_SIZE value=20></applet>
18 22小试身手 public void inito String paramete; parameter-getParameter("MESSAGE; if (parameter =nul) message≡ parameter; parameter=getParameter (FONT ) if(parameter=null) font to use=parameter, parameter=getParameter(POINT SIZE; if (parameter!=null) point size=Integer parseInt(parameter);
18 2.2 小试身手 public void init() { String paramete; parameter=getParameter("MESSAGE"); if (parameter!=null) message=parameter; parameter=getParameter("FONT"); if (parameter!=null) font_to_use=parameter; parameter=getParameter("POINT_SIZE"); if (parameter!=null) point_size=Integer.parseInt(parameter); }
19 23图形处理 23.1图形坐标系统 任何与绘图有关的操作0 第一个要用的是 java. awt. Graphics类 Graphics类的对象不是 由new产生的而是由系 统或其他方式直接将生好的 Graphics对象当作 方法的参数再交给程序设计者去处理例如: paint(Graphics g)
19 2.3 图形处理 2.3.1图形坐标系统 任何与绘图有关的操作 第一个要用的是 java.awt.Graphics类 Graphics类的对象不是 由new产生的,而是由系 统或其他方式直接将生好的Graphics对象当作 方法的参数,再交给程序设计者去处理.例如: paint(Graphics g) x y 0
20 23图形处理 Graphics的方法 paint( graphics g) igclearRect(; g copyArea 0; g. drawAre0; g drawLine; g. drawOval0: g. drawRecto; g drawPolygon(; g. fillArco; g. HillOval0; g. fillPolygen0; g. fillRecto; g.getcoloro g. getFonto g.setFonto; gset ColorO; g. getFontMetricso g. fillRoundrecto
20 2.3 图形处理 • Graphics的方法 paint(Graphics g) { g.clearRect(); g.copyArea(); g.drawAre() ; g.drawLine(); g.drawOval();g.drawRect(); g.drawPolygon(); g.fillArc(); g.fillOval(); g.fillPolygen(); g.fillRect(); g.getColor(); g.getFont() g.setFont(); g.setColor(); g.getFontMetrics() g.fillRoundRect() }