Chapter 6 notes Important stuff: 220 Math table 221,2 ff. 6.8 (most important in chapter) 6.10 6.11 254-6 line 28, p.256 1st para. Math class static methods: always: Math.method_name Math.sqrt(x*x+y*y) 2 * Math.PI * radius type promotion/coercion: "little" to "big" OK e.g. int to float "big" to "little" syntax error: e.g. double to float. (cast) needed int i; double d; d = i; //OK i = d; //syntax error. allowable in C++ i = Math.sqrt(x); //syntax error. sqrt returns double i = (int)Math.sqrt(x); //OK java.awt.Container; //GUI components can be attached to a Container Container mycontainer = getContentPane(); //no new. content pane of applet mycontainer.add(a_GUI_component_ref) //add a GUI object to the //applet's content pane java.awt.FlowLayout; //simplest layout manager. left to right, top to bottom java.awt.event.ActionEvent; //info about the action that occurred java.awt.event.ActionListener; //Interface public class MyCoolApp extends JApplet implements ActionListener { JLabel mylabel = new JLabel(String) JTextField mytext = new JTextField(int size) mytext.setEditable(false) //display only, no input mytext.setText(String) //assign text mytext.getText() //returns String JButton mybutton = new JButton(String) //this applet has the event handler (it implements the actionPerformed //method of the ActionListener interface: mybutton.addActionListener(this) Container mycontainer = getContentPane() //a FlowLayout object will be the layout manager for this container: mycontainer.setLayout(new FlowLayout()) mycontainer.add(JLabel ref) mycontainer.add(JTextField ref) mycontainer.add(JButton ref) mycontainer.add(JTextArea ref) showStatus(String) //set the status bar //event handler for registered event: public void actionPerformed(ActionEvent ae) { ... javax.swing.: JOptionPane JTextArea JScrollPane JApplet JLabel JTextField JButton Method Overloading. methods with same name but arguments differ in number, types, order. return type irrelevant. int f(int) int f(float) void f(int,float) void f(float,int) int f(int,float) //syntax error int f(String) void f(String) //syntax error void f(int, float, int)