I'm trying to draw on the JPanel panel, but for some reason nothing shows up when I run the code. Is it because I have to set the panel on which to draw? If so, can someone please tell me how to do this, or just tell me what the problem is lol. Thanks
(Btw I do have a main method that makes a new PongDrawer and runs the display() method)
import javax.swing.*; import java.awt.*; import java.awt.event.*; @SuppressWarnings("serial") public class PongDrawer extends JPanel implements ActionListener, KeyListener { JFrame table; JLabel score; JPanel panel; JPanel scorePanel; Timer ballTimer; int ballSpeed; public PongDrawer(){ table = new JFrame("Pong"); panel = new JPanel(); table.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); table.setContentPane(panel); scorePanel = new JPanel(); scorePanel.setSize(700,50); table.add(scorePanel, BorderLayout.NORTH); panel.setBackground(Color.GRAY); score = new JLabel("score Test"); scorePanel.add(score, BorderLayout.CENTER); ballSpeed = 500; ballTimer = new Timer(500, this); addKeyListener(this); } @SuppressWarnings("deprecation") public void display(){ table.pack(); table.resize(700,500); table.setVisible(true); repaint(); } public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.BLACK); g.drawLine(0, 100, 700, 100); } public void actionPerformed(ActionEvent e){ } public void keyPressed(KeyEvent e){ int keyCode = e.getKeyCode(); //does the corresponding action for each key pressed switch(keyCode){ case KeyEvent.VK_UP: break; case KeyEvent.VK_DOWN: break; case KeyEvent.VK_W: break; case KeyEvent.VK_S: break; } } public void keyTyped(KeyEvent e){} public void keyReleased(KeyEvent e){} }