I have now decided to make a 4k game, but I dont know how to make the gui or what to call it.
I usually run a main method which creates a new JFrame.
Then I make a class file name GUI extending JPanel an add it to the frame.
the GUI controls the entire game then.
But how is the cheapest way (of size) to do this?
And is it alowed to extend other classes?
This is how I have made the basics of my 4k game. What should I do better since its already at 1.87k?
public class A extends JPanel implements ActionListener, KeyListener{
int i = 0;
public static void main(String[] args) {
A a = new A();
a.addKeyListener(a);
a.setPreferredSize(new Dimension(600,400));
a.setBackground(Color.black);
a.setFocusable(true);
JFrame frame = new JFrame("");
frame.getContentPane().add(a);
frame.pack();
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Timer timer = new Timer(20,a);
timer.start();
}
public void paint(Graphics g){
super.paint(g);
g.drawLine(i,3,100,100);
}
public void keyTyped(KeyEvent arg0) {
}
public void keyPressed(KeyEvent arg0) {
//Keys
i-=100;
}
public void keyReleased(KeyEvent arg0) {
}
public void actionPerformed(ActionEvent arg0) {
//Game loop
i++;
repaint();
}
}
The i variable is just for testing the game loop and the keys