Я сделал сообщение ранее, которое не было четким! Вот код. Это - пример кода, который я тестирую, чтобы видеть, работает ли это над моей человечностью!
// using drawLine to connect the corners of s panel
import java.awt.Graphics;
import javax.swing.JPanel;
public class DrawPanel extends JPanel
{// draws an x from the corners of the panel
public void paintComponent( Graphics g )
{
// calls paintComponent to ensure the panel displys correctly
super.paintComponent( g );
int width = getWidth();
int height = getHeight();
// draw line from the upper-left to lower-right corners
g.drawLine( 0, 0, width, height );
// draw line from then upper-right to the lower-left corners
g.drawLine( width, 0, 0, height);
System.out.println( "paintComponent Called");
} // end method paintComponent
} // end class DrawPanel
And the driver code:
// application to display a DrawPanel
import javax.swing.JFrame;
public class DrawPanelTest
{
public static void main(String[] args)
{
//create a panel that contains our drawing
DrawPanel panel = new DrawPanel();
// create a new frame to hold the panel
JFrame application = new JFrame("Drawing Diagonals");
// set the frame to exit when closed
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel); // adds panel to the frame
application.setSize(300, 300); // set the size
}
}
Когда я компилирую его и выполняю его, ничто не показывает! Это, как предполагается, открывается окно и отображает графику!!
Это работает над другими системами, но не над моей человечностью! Что могло быть неправильным?
Спасибо
Добавьте application.setVisible(true);
в Вашем классе DrawPanelTest
public class DrawPanelTest {
public static void main(String[] args) {
// create a panel that contains our drawing
DrawPanel panel = new DrawPanel();
// create a new frame to hold the panel
JFrame application = new JFrame("Drawing Diagonals");
// set the frame to exit when closed
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel); // adds panel to the frame
application.setSize(300, 300); // set the size
application.setVisible(true);
}
}