Hi guys. So i create little program. So window is in full screen. But i need help with paint method. I think I this method not understeand fully. So code:
package Test; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.*; import java.util.Random; public class Main extends JFrame { Graphics g; public static void main(String[]args) { DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN); Main main = new Main(); main.run(dm); } public Main() { addKeyListener(new KeysListener()); } public void run(DisplayMode dm) { setBackground(Color.black); setForeground(Color.pink); setFont(new Font("Arial",Font.BOLD,40)); Screen s = new Screen(); try { s.setFullScreenWindow(dm, this); try { Thread.sleep(30000); }catch(Exception e) { } }finally{ s.restoreWindow(); } } public void paint(Graphics g) { g.fillRect(300, 300, 250, 40); } public void repaint() { Random rand = new Random(400); g.setColor(Color.RED); g.fillRect(rand.nextInt(), rand.nextInt(), 200, 50); System.out.println("ADSdas"); } public class KeysListener implements KeyListener { Graphics g2 = null; public void keyPressed(KeyEvent e) { int s = e.getKeyCode(); if(s ==e.VK_O) { System.exit(0); } if (s == e.VK_Z) { repaint(); } } @Override public void keyReleased(KeyEvent e) { } @Override public void keyTyped(KeyEvent arg0) { // TODO Auto-generated method stub } } }
So, paint method works perfectly. He paint rectangle. Good. But I dont know how using ,,paint2'' method. I need when you press z button, ,,paint2'' method draw Oval in random cordination. So instead ,,paint2'' method i using repaint() but i dont know nothing about paint methods and so on. So you can tell me how using ,,paint2'' method? Thanks.. Now when i run program, i get a lot of error..
Thanks for help..
P.S i thought about new object Graphics g2...