/* * Copyright (c) 1999-2002, Xiaoping Jia. * All Rights Reserved. * * Modified to be an application rather than an applet. * Barbara Lerner Sept. 4, 2006 */ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Toolkit; import javax.swing.JComponent; import javax.swing.JFrame; /** * A simple Java application. It displays a text message and an image of the planet Venus. */ public class HelloFromVenusSimple extends JComponent { /** * Draw the component * @param g the graphics object to draw on. */ public void paintComponent(Graphics g) { // Find out how big the panel is. Dimension d = getSize(); // Make the background black by drawing a black rectangle the size of the panel. g.setColor(Color.black); g.fillRect(0, 0, d.width, d.height); // Select the font and color for the message. 24 is the font size. // The color is specified in RGB. Each parameter can range from 0 to 255. g.setFont(new Font("Helvetica", Font.BOLD, 24)); g.setColor(new Color(255, 215, 0)); // gold color // Draw the message at coordinate (40, 25), 40 pixels from the left and 25 pixels from the // top of the panel. g.drawString("Hello from Venus", 40, 25); // Read the image from the file and draw it at (20, 60). g.drawImage(Toolkit.getDefaultToolkit().getImage("Venus.gif"), 20, 60, this); } // Creates the user interface public static void main (String[] args) { // Create the window and set its size. JFrame f = new JFrame(); f.setSize(new Dimension(300, 350)); // Create the panel that will display the image and text HelloFromVenusSimple venusPanel = new HelloFromVenusSimple(); // Add the venus panel to the center of the window Container contentPane = f.getContentPane(); contentPane.add(venusPanel, BorderLayout.CENTER); // Display the window. f.setVisible(true); } }