Hi,
I wrote a simple program that should display the text (with specific fonts), one color background and drawing. I tried to run the program but it didn't work. Any suggestions?
What is the method of Graphics that allow you to draw within the program? eg java.awt.Graphics but I don't know how to add the code into that program.
DrawGraphics.java
import java.awt.*;
import javax.swing.*;
public class DrawGraphics extends JFrame {
private JLabel label1;
private JLabel label2;
private JLabel label3;
public DrawGraphics() {
super("Testing JLabel");
setLayout(new FlowLayout());
label1 = new JLabel("Workshop 3: Graphics");
label1.setFont(new Font("monospaced", Font.BOLD+Font.ITALIC, 18));
Color background = new Color(70, 80, 70);
label1.setBackground(background);
add(label1);
}
}
LabelFrame.java
import javax.swing.JFrame;
public class LabelFrame {
public static void main(String[] args) {
DrawGraphics labelFrame = new DrawGraphics();
labelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
labelFrame.setSize(300, 250);
labelFrame.setVisible(true);
}
}