Olá. Estou estudando Java em casa, com o livro Deitel 8ªe - Java Como Programar. Estou no Capítulo 4 Seção 14, onde ensina o seguinte:
Código:import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel {
public void paintCompanent(Graphics g) {
super.paintComponent(g);
int width = getWidth();
int height = getHeight();
g.drawLine(0, 0, width, height);
g.drawLine(0, height, width, 0);
}
}
import javax.swing.JFrame;
public class DrawPanelTest {
public static void main(String[] args) {
DrawPanel panel = new DrawPanel();
JFrame application = new JFrame();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add (panel);
application.setSize(250, 250);
application.setVisible(true);
}
}
Essa é a saída que printei do livro:
[img]http://i.imgur.com/pR06mef.png[/img]
Essa é a saída que eu obtive:
[img]http://i.imgur.com/iYBxK5h.png[/img]
As saídas estão diferentes. O que tem de errado?