Hi, I have a external class with paint(Graphics g) method and the class itself is working great. I can get it visible by launching it from my launch class by doing add(new Laatikko()); but when I am trying to get it work from third class it wont show up. Basicly I have main class and there I need to run this class which isnt showing up.
package net.viped;
import java.awt.Color;
import javax.swing.JFrame;
public class Launch extends JFrame {
public Launch() {
add(new grafiikkaa());
setSize(300, 300);
setBackground(Color.black);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Launch();
}
}
package net.viped;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferStrategy;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class grafiikkaa extends JPanel implements ActionListener{
int y=100;
Saie saie = new Saie();
public grafiikkaa() {
addKeyListener(new LueNappaimet());
initGame();
Laatikko laa = new Laatikko();
System.out.println(laa.isDisplayable());
add(new Laatikko());
System.out.println(laa.getGraphics());
System.out.println(laa.getBounds());
setFocusable(true);
this.repaint();
}
public void drawStuff() {
Graphics g = null;
Laatikko laa = new Laatikko();
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.blue);
g.fillRect(50, y, 10, 10);
g.setColor(Color.red);
g.fillRect(50, 70, 10, 10);
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
public void initGame() {
saie.start();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
public class LueNappaimet extends KeyAdapter{
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_UP) {
System.out.println("up");
y--;
repaint();
}
}
}
public class Saie extends Thread {
public void run() {
while(true) {
try {
sleep(10);
repaint();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
package net.viped;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Toolkit;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Laatikko extends JLabel{
int width = 10;
int height = 10;
int x = 100;
int y = 50;
public Laatikko() {
setBounds(x, y, width, height);
setVisible(true);
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.white);
g.fillRect(100, 150, 10, 10);
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
}
Thanks for advance.