|
You will improve the following very simple exemple by adding some asked modififations to it.
| HelloWordFrame |
|---|
/** Simple Java 2D Example
*
* @version 0.9 12/07/2001
* @author Pascal Vuylsteker
*/
import javax.swing.*;
public class HelloWordSimple
{ public static void main(String[] args)
{ HelloWordFrame frame = new HelloWordFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class HelloWordFrame extends JFrame
{ public HelloWordFrame()
{ setTitle("Hello World !! ");
setSize(300,200);
HelloPanel panel = new HelloPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
}
}
class HelloPanel extends JPanel
{ public void paintComponent(Graphics g)
{ super.paintComponent(g);
g.drawString("Hello again...", 20, 20);
}
}
|
Add some comments in the code
import java.awt.*;
Add some comments in the code
Toolkit Class
Toolkit Class
Add some comments in the code
showInputDialog from JOptionPane...
String name = JOptionPane.showInputDialog("What is your Name");
use a Font object, get a FontMetrics from it, and then get the stringWidth
package, import, javac -d, CLASSPATH, package name : reversed internet domain name
|
| See the "Links" link above to find out the sources of the proposed informations Pascal Vuylsteker / eScience / Computer Science / ANU |
Last modified: 2/4/2002
TOC - Print |
Send your comments at : <Hugh.Fisher@anu.edu.au> |