Проблемы с отображением пользовательского JComponent - PullRequest
0 голосов
/ 16 мая 2011

Эй, ребята, у меня проблемы с чем-то, что, кажется, должно быть намного проще. Я просто не могу показать свой простой пользовательский JComponent! Я использую Абсолютное Позиционирование по своему выбору, и я не уверен, может ли это быть причиной некоторых проблем. Любой совет и / или решение <с благодарностью. Thankss! </p>

(вот мой код)

public class XtremePaintballNetwork {

    private static JFrame _xpbnWindow;
    private static JTextField _chatTextField;
    //private static Map _map;
    private static Map _map;

    public static void main(String[] args) {
        // Set up main window
        _xpbnWindow = new JFrame("Xtreme Paintball Network");
        _xpbnWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        _xpbnWindow.setSize(400, 300);;
        //_xpbnWindow.setBackground(Color.white);
        //_xpbnWindow.getContentPane().setBackground(Color.white);
        //_xpbnWindow.pack();
        _xpbnWindow.setVisible(true);


        addComponentsToPane();

        _xpbnWindow.addComponentListener( new ComponentListener() {
            public void componentHidden(ComponentEvent e) {}
            public void componentMoved(ComponentEvent e){}
            public void componentResized(ComponentEvent e) {
                adjustBounds();
            }
            public void componentShown(ComponentEvent e) {}
        });

        _xpbnWindow.repaint();
    }

    private static void addComponentsToPane() {
        Container pane = _xpbnWindow.getContentPane();

        // Use Absolute Positioning
        pane.setLayout(null);

        // Create GUI components
        _map = new Map();
        _chatTextField = new JTextField();

        // Add components to pane
        pane.add(_map);
        pane.add(_chatTextField);

        // Calculate and set Bounds
        adjustBounds();
    }

    private static void adjustBounds() {
        Container pane = _xpbnWindow.getContentPane();


        // Use 'null' layout -> Absolute Positioning
        Insets insets = pane.getInsets();
        Dimension _windowDimension = pane.getSize();
        Dimension _chatDimension = _chatTextField.getPreferredSize();
        /*_map.setBounds(0, insets.top, _windowDimension.width - insets.left - insets.right,
                _windowDimension.height - insets.top - insets.bottom);*/
        _map.setBounds(10, 10, 100, 100);
        _chatTextField.setBounds(0, _windowDimension.height - _chatDimension.height - insets.top - insets.bottom,
             _windowDimension.width - insets.left - insets.right, _chatDimension.height);

    }

}

и вот простой класс JComponent

public class Map extends JComponent{


    //@Override
    protected void PaintComponent(Graphics g){
        super.paintComponent(g);
        g.drawLine(0, 0, 70, 70);
        g.drawString("string",20,20);
    }
}

По сути, моя проблема в том, что в моем JFrame ничего не появляется ...: / Help!

1 Ответ

2 голосов
/ 16 мая 2011

Имя метода paintComponent.Он начинается в нижнем регистре: Ссылка

...