View Single Post
  #1 (permalink)  
Old 10-18-2007, 10:29 PM
Bojevnik Bojevnik is offline
Member
 
Join Date: Aug 2007
Posts: 13
Bojevnik is on a distinguished road
My program doesnt display anything
Hi i've got a problem with my code it doesnt display picture like or anything for that matter, it just gives me black window.

Code:
package igra; import java.lang.*; import java.io.*; import java.awt.*; import javax.swing.*; import java.util.*; import java.awt.image.*; import java.net.*; import java.awt.event.*; /** * * @author Bojevnik */ public class GlavnoOkno extends JFrame implements { final int SCREENWIDTH =700; final int SCREENHEIGHT = 700; boolean RESIZABLE=false; JPanel panela; BufferedImage backBuffer; Graphics2D g2d; /** Creates a new instance of GlavnoOkno */ public GlavnoOkno() { this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(SCREENWIDTH,SCREENHEIGHT); this.setResizable(RESIZABLE); panela = new Vsebina(); this.setLayout(null); panela.setBounds(0,0,SCREENWIDTH,SCREENHEIGHT); this.add(panela); } private class Vsebina extends JPanel implements Runnable,KeyListener,MouseListener { Image ozadje; Toolkit tk; public void update(Graphics g){ //g2d.drawImage(ozadje,0,0,SCREENWIDTH-1,SCREENHEIGHT-1,this); g2d.setColor(Color.RED); g2d.drawLine(0,0,500,500); paint(g); } public void paint(Graphics g){ g.drawImage(backBuffer,0,0,this); } Vsebina(){ backBuffer = new BufferedImage(SCREENWIDTH, SCREENHEIGHT,BufferedImage.TYPE_INT_RGB); g2d = backBuffer.createGraphics(); tk = Toolkit.getDefaultToolkit(); ozadje = tk.getImage(getFURL("img/testOzadje.jpg")); this.addMouseListener(this); this.addKeyListener(this); this.setFocusable(true); Thread s = new Thread(this); if(s!=null) s.start(); } public void run(){ int a=0; while(a<10){ repaint(); a++; try{ Thread.sleep(1000); } catch(Exception ex){ System.exit(-1); } System.out.println("dela");} } public URL getFURL(String url){ URL tempURL=null; File temp; try{ temp = new File(url); tempURL = temp.toURL(); if (tempURL==null) throw new Exception("sss"); } catch(Exception ex){ System.err.print("NAPAKA pri branju slike"); System.exit(-1); } return tempURL; } public void keyReleased(KeyEvent ke){} public void keyPressed(KeyEvent ke){if (ke.getKeyCode()==27) System.exit(1);} public void keyTyped(KeyEvent ke){} public void mouseExited(MouseEvent me){} public void mouseEntered(MouseEvent me){} public void mouseClicked(MouseEvent me){} public void mouseReleased(MouseEvent me){} public void mousePressed(MouseEvent me){System.exit(0);} } }
__________________
I HATE SMURFS!!!!!
Reply With Quote
Sponsored Links