Hello..

I am developing a graphics application. I am playing a video in my application and when I press any key , it should stop currently playing video and should start displaying other images.Everything went well except when I press any key the video is getting stopped but
the screen is not getting repainted..(i.e the screen turns into black and stucks)

I thought that repaint() method is not working and but the fault is not with repaint method.
When I test the repaint method with sample code, its working but when i test the same method with my original code its not getting executed.. I am thinking that the fault is in way of
stopping the video and painting the screen again..

Any suggestions..

Recommended Answers

All 7 Replies

Without seeing your code how can we comment?

calls to repaint should cause a later call to paintComponent?
Is paintComponent being called?
Add printlns to show call to repaint and call to paintComponent.

Without seeing your code how can we comment?

import java.awt.*;
import java.net.*;
import java.io.*;
import javax.swing.JFrame;
import javax.swing.*;
import java.awt.event.*;

public class FullScreenTest extends JFrame implements KeyListener{
int click=0;
    JProgressBar jp;  

     String file="scanning ...file";
			   FileInputStream fis;
BufferedReader br=null;
String currentFile;
JLabel win=new JLabel(new ImageIcon("win-logo.png"));
JLabel avast=new JLabel(new ImageIcon("my-logo.png"));


JLabel lab=new JLabel("c:\\documents\\virus.exe");

static MediaPanel mediaPanel;
    public static void main(String[] args) {

        DisplayMode displayMode;
        if (args.length == 3) {
            displayMode = new DisplayMode(
                Integer.parseInt(args[0]),
                Integer.parseInt(args[1]),
                Integer.parseInt(args[2]),
                DisplayMode.REFRESH_RATE_UNKNOWN);
        }
        else {
            displayMode = new DisplayMode(800, 600, 16,
                DisplayMode.REFRESH_RATE_UNKNOWN);
        }

        FullScreenTest test = new FullScreenTest();
        test.run(displayMode);
    }

    private static final long DEMO_TIME = 900000;


    public void run(DisplayMode displayMode) {
	
		addKeyListener(this);
        getContentPane().setBackground(Color.black);
        setForeground(Color.white);
        setFont(new Font("Dialog", 0, 24));
		setLayout(new BorderLayout());
      


URL test=null;
try
					 {test=new URL("file:///C:/Users/Harinath/Desktop/myvideofile.mpg");   }catch(Exception ex1){}
               FullScreenTest.mediaPanel = new MediaPanel( test );
		//		 mediaPanel.setBounds(0,0,600,600); 
               	 add( mediaPanel ,BorderLayout.CENTER);
				 

        SimpleScreenManager screen = new SimpleScreenManager();
        try {
            screen.setFullScreen(displayMode, this);

         try {
                Thread.sleep(DEMO_TIME);
            }
            catch (InterruptedException ex) { }
}catch(Exception ew){}

        finally {
            screen.restoreScreen();
        }
    }


    public void paint(Graphics g) {
		
   }
	
	
public void keyTyped(KeyEvent e){

	//JOptionPane.showMessageDialog(this,"why do u think it is not executing??");


/*************************** This code not working *************************************/
try{
FullScreenTest.mediaPanel.callStop();  /* callStop() method code is at end of the code */
remove(FullScreenTest.mediaPanel);
}catch(Exception eq){}
repaint();
invalidate();


setLayout(null);


 	try{

	fis=new FileInputStream("exefiles.txt");
	br=new BufferedReader(new InputStreamReader(fis));
   
}catch(Exception e3){}


		      jp=new JProgressBar();
			  jp.setBorderPainted(false);


jp.setStringPainted(false);
jp.setForeground(new Color(67,127,209));
jp.setBackground(Color.black);
lab.setForeground(new Color(184,188,212));
jp.setBounds(20,390,760,20);
add(jp);
lab.setBounds(20,430,700,28);
add(lab);
win.setBounds(10,10,150,150);
avast.setBounds(200,180,330,250);
add(win);
add(avast);

for(int i=0;i<=100;i++)
		{jp.setValue(i);

try{
		for(int count=1;count<=25;count++){
currentFile=br.readLine();
if(currentFile==null){br.reset();i=100; jp.setValue(100); break; }

lab.setText("Scanning...."+currentFile);Thread.sleep(20);}
	     }catch(Exception e7){}
		}


try{

lab.setForeground(Color.cyan);
remove(jp);
lab.setText("SCAN COMPLETED SUCCESSFULLY....");
Thread.sleep(2500);
for(int u=10;u>=0;u--){
lab.setText("Your computer will restart in "+u+ " seconds...");
Thread.sleep(1000);
//dispose();

}}catch (Exception e8){}


}
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
	
	}
/* this method is in MediaPanel.java and is called from FullScreenTest.java when key pressed*/

public  void callStop()
		{
			try{mediaPlayer.stop();
			mediaPlayer.close();
		}catch(Exception e){}
public void paint(Graphics g) {
 
}

That looks like a black window to me!

catch(Exception ew){}
...
catch(Exception e3){}
...
catch (Exception e8){}
...
catch(Exception e){}
(etc)

This is about as dumb a thing as its possible to do in Java. You are saying "if anything goes wrong in my program detect it, diagnose it, document it, then throw all that away and don't tell me"
Before wasting another minute on this, put an e.printStackTrace(); in every catch block and see what results that gives.

There's no code in paint() method because there is no requirement.

I am not worried about exceptions here in this case since it has no complex code to throw
such Heavy Exceptions ..
However ..
The only point is that code in keyTyped() method is not updating the components to window .

This code not working

Why is it NOT working? Does it throw an Exception?
See James's recommendations.

What happens if you copy the statements that are not working to another place and execute them without having to wait on keyTyped?

There's no code in paint() method because there is no requirement.

So you have a JFrame ibut there's no requirement to paint it or any of its components.

I am not worried about exceptions here in this case since it has no complex code to throw such Heavy Exceptions ..

AFAIK there's only one "weight" for Exceptions and that is "heavy", as in "your code could not be executed". It doesn't take much complexity to generate a null pointer exception, for example.

There's none so blind as those who will not see.
Good luck with your program.
J

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.