Main Class
package dymetric;
public class Dymetric {
public static void main(String[] args) {
Facet lcd = new Facet();
lcd.setVisible(true);
}
}
Window Display
package dymetric;
import java.awt.*;
import javax.swing.*;
public class Facet extends JFrame {
private Container face;
private CanvasFeel canvas;
private ImageIcon logo;
public Facet() {
super("A window that will hold a Canvas");
setSize(780,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(true);
logo = new ImageIcon(getClass().getResource("studyingPays.png"));
this.setIconImage(logo.getImage());
face = this.getContentPane();
face.setBackground(Color.PINK);
canvas = new CanvasFeel();
face.add(canvas, BorderLayout.NORTH);
}
}
Java code for Canvas class
package dymetric;
import java.awt.*;
public class CanvasFeel extends Canvas {
public CanvasFeel() {
setBackground(Color.YELLOW);
}
}
Important:
Get the logo image(.png) used in the code here
and save it to the same folder(directory) as your code files.
For NetBeans, this folder should be
C:\Users\user_name\Documents\NetBeansProjects\Dymetric\src\dymetric.
Note: The code module for our main class will remain the
same for the rest of the demonstrations in this category.
Hence it will be left out hence forth.
Drawing Reference
For a thorough explanation of drawing graphics
in Java, please see the following link:
(Just to mention; the tutorial at this link makes heavy use
of applets which are no longer supported - deprecated - by modern
browsers. To try out the lessons shown, you can run the applets as
stand alone programs by changing the following lines in our facet
class from
private CanvasFeel canvas;
canvas = new CanvasFeel();
face.add(canvas, BorderLayout.NORTH);
to
private AppletClassName a_var_name;
a_var_name = new AppletClassName();
face.add(a_var_name, BorderLayout.NORTH);
)
David J. Eck's Introduction to Programming Using Java
- largely apt for Java beginners; Knock your head out!!