工学jaa常用类简介.pptxVIP

  • 1
  • 0
  • 约4.88千字
  • 约 50页
  • 2019-11-28 发布于上海
  • 举报
第八讲 Java常用类简介;主要内容:;类的介绍/Object;类的介绍/Object;class A{ public String toString(){ return A is for ObjectTest class; } } public class ObjectTest { public static void main(String[] s){ A a1 = new A(); A a2 = new A(); A a3 = a1; System.out.println(a1.equals(a1) is + a1.equals(a1)); System.out.println(a1.equals(a2) is + a1.equals(a2)); System.out.println(a1.equals(a3) is + a1.equals(a3)); System.out.println(a1.toString()); System.out.println(a1 is a instance of class + a1.getClass().getName()); } };类的介绍/Math;public class MathTest{ public static void main(String[] s){ System.out.println(sin(π/4) is + Math.sin(Math.PI/4.0)); System.out.println(2的4次方是 + Math.pow(2,4)); System.out.println(以e为底的e的对数是 + Math.log(Math.E)); System.out.println(81的平方根是 + Math.sqrt(81)); } };import java.awt.*; import java.awt.event.*; class RandomFrame extends Frame implements ActionListener{ RandomFrame(){ this(RandomFrame); } RandomFrame(String title){ super(title); add(pane = new Panel()); setPane(); pack(); Dimension dm = getSize(); Dimension ss = getToolkit().getScreenSize(); setCenter(ss, dm); 转下页;接上页 addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } }); } //构造方法结束 private void setCenter(Dimension screen, Dimension frame){ int x = screen.width/2 - frame.width/2; int y = screen.height/2 - frame.height/2; setLocation(x,y); } 转下页;接上页 private void setPane(){ tfd = new TextField(20); tfd.setFont(new Font(Tahoma, Font.BOLD, 16)); pane.add(tfd); btn = new Button(RandomNumber Generator); btn.addActionListener(this); pane.add(btn); } public void actionPerformed(ActionEvent ae){ Button b = (Button)ae.getSource(); if(b == btn){ String s = Double.toString(Math.random()); tfd.setText(s); } } 转下页;接上页 private Button btn; private TextField tfd; private Panel pane; } //RandomFrame

文档评论(0)

1亿VIP精品文档

相关文档