package Principal;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
public class Desenho {
public static void main(String[] args){
JanelaDesenho jd = new JanelaDesenho();
jd.setVisible(true);
desenhar();
}
public static void desenhar(){
Canvas c = JanelaDesenho.getCanvas();
Graphics g = c.getGraphics();
c.setBackground(Color.WHITE);
g.setColor(Color.BLACK);
g.fillRect(0, 0, 100, 100);
}
}
package Principal;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Canvas;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
public class JanelaDesenho extends JFrame {
private JPanel contentPane;
private static Canvas canvas;
/*
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JanelaDesenho frame = new JanelaDesenho();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
*/
/**
* Create the frame.
*/
public JanelaDesenho() {
setTitle("Digger");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 497, 505);
contentPane = new JPanel();
contentPane.setToolTipText("");
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
getCanvas().setBounds(0, 0, 481, 466);
contentPane.add(getCanvas());
}
public static Canvas getCanvas(){
if(canvas == null){
canvas = new Canvas();
}
return canvas;
}
}
package Principal;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Canvas;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
public class JanelaDesenho extends JFrame {
private JPanel contentPane;
private static Canvas canvas;
/*
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JanelaDesenho frame = new JanelaDesenho();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
*/
/**
* Create the frame.
*/
public JanelaDesenho() {
setTitle("Digger");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 497, 505);
contentPane = new JPanel();
contentPane.setToolTipText("");
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
getCanvas().setBounds(0, 0, 481, 466);
contentPane.add(getCanvas());
}
public static Canvas getCanvas(){
if(canvas == null){
canvas = new Canvas();
}
return canvas;
}
}