import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
public class ColorDemo {
class GraphicPane extends JComponent {
public GraphicPane() {
super();
}
@Override public void paint(Graphics g) {
g.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 14));
g.setColor(Color.ORANGE);
g.drawString("Hello, World! (orange)", 30, 30);
g.setColor(new Color(250, 100, 120));
g.drawString("Hello, World! (red ... almost)", 80, 80);
}
}
public ColorDemo() {
JFrame jf = new JFrame("Hello, World!");
GraphicPane gp = new GraphicPane();
jf.setBounds(0,0, 800, 600);
jf.setLayout(new BorderLayout());
jf.add(gp, BorderLayout.CENTER);
// Remember, the method show() is deprecated
jf.setVisible(true);
}
public static void main(String[] args) {
new ColorDemo();
}
}