import java.io.File;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.awt.TextArea;
import java.awt.Font;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.FileDialog;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.print.DocFlavor.URL;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.event.MouseInputAdapter;

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.Timer;
import javax.swing.tree.*;
import javax.swing.text.html.*;

public class InfiniteChatRoomUI implements ActionListener,KeyListener{
	
	JFrame iFrame;
	JPanel iPaneLbl;
	ImagePanel iChatLogo;
	JLabel iLabel; 
	Image iChat_icon,iChat_logo;
	JTextField userInput;
	TextArea convOutput;
	JButton send,save;
	FileDialog saveTo;
	private Timer timer=null;
	boolean focused = false;
	String iName,iReceiver,currentMsg;
	StringBuffer conversation;
	
	InfiniteChatClient iClient;
	/**
	 * Method InfiniteChatConversationRoom
	 * @throws IOException 
	 *
	 *
	 */
	public InfiniteChatRoomUI(InfiniteChatClient iClientOb,String forUser) throws IOException{
		iClient=iClientOb;
		iName=iClient.userName;
		iReceiver=forUser;
		
		conversation=new StringBuffer("");
		
		iFrame=new JFrame("Conversation Room");
		

		iFrame.setLayout(null);
		iFrame.setBounds(180,80,430,420); 
		iFrame.setResizable(false);
		
		
	
		
		
		iPaneLbl=new JPanel(null);
		iPaneLbl.setBounds(0,0,600,70);
		iPaneLbl.setBackground(Color.white);
		java.net.URL url;
		url = getClass().getResource("san.PNG");
		Image image = Toolkit.getDefaultToolkit().getImage(url);
		

		iFrame.setIconImage(image);
		
		iChatLogo=new ImagePanel(image);
		iChatLogo.setBounds(0,0,110,70);
		
		iLabel=new JLabel("Conversation with "+iReceiver+" :");
		iLabel.setBounds(125,15,200,50);
		iLabel.setForeground(Color.black);
		iLabel.setFont(new Font("Helvitica",Font.BOLD,15));
		
		save=new JButton("Save");
		save.setBounds(340,15,80,40);
		save.addActionListener(this);
		
		iPaneLbl.add(iChatLogo);
		iPaneLbl.add(iLabel);
		iPaneLbl.add(save);
		iFrame.add(iPaneLbl);
		
		convOutput=new TextArea("",0,0,1);
		convOutput.setBackground(Color.WHITE);
		convOutput.setBounds(10,80,410,250);
		convOutput.setEditable(false);
		iFrame.add(convOutput);
		
		userInput=new JTextField("");
		userInput.setBounds(10,340,330,40);
		userInput.addKeyListener(this);
		iFrame.add(userInput);
		
		send=new JButton("Send");
		send.setBounds(340,340,80,40);
		send.addActionListener(this);
		send.addKeyListener(this);
		iFrame.add(send);
		
		convOutput.addMouseListener(new MouseInputAdapter() {
			public void mouseClicked(MouseEvent me) {
				focused = true;
				if(timer != null)timer.stop();
			}
		});
		
		iFrame.addWindowListener(new WindowAdapter(){
				 
						public void windowActivated(WindowEvent e) {
							focused = true;
							if(timer != null)timer.stop();
						}

						public void windowDeactivated(WindowEvent e) {
							focused = false;
						}

						

					
			
				public void windowClosing(WindowEvent e){
					
					iClient.removeRoom(iReceiver);
					iFrame.dispose();
				}
			
		});
		
		iFrame.setVisible(true);
		iFrame.requestFocus();

		//sun.awt.SunToolkit tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
		//hwnd = tk.getNativeWindowHandleFromComponent(this);
		timer = new Timer(500,new FlashwindowListener(iFrame));
		focused = false;
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==send){
			send_message();
		}
		if(e.getSource()==save){
			save_file();
		}
	}
	
	public void keyPressed(KeyEvent e){
		if(e.getKeyChar()=='\n'){
			send_message();
		}
	}	
	public void keyReleased(KeyEvent e){}
	public void keyTyped(KeyEvent e){}
	
	public void send_message(){
		currentMsg=userInput.getText();
		iClient.send_Message("MESSAGETO "+iReceiver+" "+iName+" : "+currentMsg);
		userInput.setText("");
		conversation.append("\n"+iName+" : "+currentMsg);
		currentMsg="\n"+iName+" : "+currentMsg;
		convOutput.append(currentMsg);
	}
	
	public void save_file(){
		saveTo=new FileDialog(iFrame,"Save as...",FileDialog.SAVE);
		saveTo.setVisible(true);
		String dirname=saveTo.getDirectory();
		String fname=saveTo.getFile();
		FileOutputStream fout=null;
		if(fname.equals(null)){
			return;
		}
		else{
			fname=dirname+fname;
			try{
				fout=new FileOutputStream(fname);	
			}catch(FileNotFoundException e){
				System.out.println(e);
				return;
			}
			try{
				fout.write(conversation.toString().getBytes());
			}catch(IOException e){
				System.out.println(e);
				return;
			}
		}
	}
}

Hi friends....
I have a demo chat program which has an error line
"timer = new Timer(500,new FlashwindowListener(iFrame));" in myecllipse.
System not resolves "FlashwindowListener(iFrame))".
Where I need to edit or add, I don't know...
Anyone help plz..............

Did you write this code? What do you understand to be the intention of line 155?

package Client;


import java.io.IOException;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.awt.TextArea;
import java.awt.Font;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.FileDialog;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class InfiniteChatRoomUI implements ActionListener,KeyListener{
	
	JFrame iFrame;
	JPanel iPaneLbl;
	ImagePanel iChatLogo;
	JLabel iLabel;
	Image iChat_icon,iChat_logo;
	JTextField userInput;
	TextArea convOutput;
	JButton send,save;
	FileDialog saveTo;
	
	String iName,iReceiver,currentMsg;
	
	InfiniteChatClient iClient;
	/**
	 * Method InfiniteChatConversationRoom
	 *
	 *
	 */
	public InfiniteChatRoomUI(InfiniteChatClient iClientOb,String forUser){
		iClient=iClientOb;
		iName=iClient.userName;
		iReceiver=forUser;
		
		iFrame=new JFrame("Conversation Room");
		iFrame.setLayout(null);
		iFrame.setBounds(180,80,600,500);
		iFrame.setResizable(false);
		
		iChat_icon=Toolkit.getDefaultToolkit().getImage("../images/iChat_icon_small.gif");
		iChat_logo=Toolkit.getDefaultToolkit().getImage("../images/iChat_logo_small.gif");
		iFrame.setIconImage(iChat_icon);
		
		iPaneLbl=new JPanel(null);
		iPaneLbl.setBounds(0,0,600,70);
		iPaneLbl.setBackground(Color.black);
		
		iChatLogo=new ImagePanel(iChat_logo);
		iChatLogo.setBounds(0,0,150,70);
		
		iLabel=new JLabel("Conversation with "+iReceiver+" :");
		iLabel.setBounds(200,15,200,50);
		iLabel.setForeground(Color.white);
		iLabel.setFont(new Font("Helvitica",Font.BOLD,15));
		
		save=new JButton("Save");
		save.setBounds(500,15,80,40);
		save.addActionListener(this);
		
		iPaneLbl.add(iChatLogo);
		iPaneLbl.add(iLabel);
		iPaneLbl.add(save);
		iFrame.add(iPaneLbl);
		
		convOutput=new TextArea("",0,0,1);
		convOutput.setBackground(Color.WHITE);
		convOutput.setBounds(10,80,580,300);
		convOutput.setEditable(false);
		iFrame.add(convOutput);
		
		userInput=new JTextField("");
		userInput.setBounds(10,400,480,40);
		userInput.addKeyListener(this);
		iFrame.add(userInput);
		
		send=new JButton("Send");
		send.setBounds(500,400,80,40);
		send.addActionListener(this);
		send.addKeyListener(this);
		iFrame.add(send);
		
		iFrame.addWindowListener(
			new WindowAdapter(){
				public void windowClosing(WindowEvent e){
					iClient.removeRoom(iReceiver);
					iFrame.dispose();
				}
			}
		);
		
		iFrame.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==send){
			send_message();
		}
		if(e.getSource()==save){
			save_file();
		}
	}
	
	public void keyPressed(KeyEvent e){
		if(e.getKeyChar()=='\n'){
			send_message();
		}
	}	
	public void keyReleased(KeyEvent e){}
	public void keyTyped(KeyEvent e){}
	
	public void send_message(){
		currentMsg=userInput.getText();
		iClient.send_Message("MESSAGETO "+iReceiver+" "+iName+" : "+currentMsg);
		userInput.setText("");
		currentMsg="\n"+iName+" : "+currentMsg;
		convOutput.append(currentMsg);
		//if (iFrame.getExtendedState() == 1)iFrame.toFront();if ((iFrame.getExtendedState() == 0) && (iFrame.isFocused() == true)){iFrame.setExtendedState(2);iFrame.toFront();}
		//iFrame.setExtendedState(0); iFrame.toFront();
		iFrame.setExtendedState(JFrame.ICONIFIED);
		iFrame.toFront();
		//iFrame.setExtendedState(JFrame.ICONIFIED);
//		iFrame.setExtendedState(JFrame.NORMAL);
//		iFrame.setExtendedState(iFrame.getExtendedState() | JFrame.ICONIFIED);
//		iFrame.setExtendedState(iFrame.getExtendedState() & (~JFrame.ICONIFIED));
		//iFrame.setAlwaysOnTop(true);
//		iFrame.setAlwaysOnTop(false); //change if hidding
//		    Runnable doRun = new Runnable() {
//		        public void run() {
//		        	iFrame.toFront();
//		       }
//		   };
//		SwingUtilities.invokeLater(doRun);


	}
	
	public void save_file(){
		saveTo=new FileDialog(iFrame,"Save as...",FileDialog.SAVE);
		saveTo.setVisible(true);
		String dirname=saveTo.getDirectory();
		String fname=saveTo.getFile();
		FileOutputStream fout=null;
		if(fname.equals(null)){
			return;
		}
		else{
			fname=dirname+fname;
			try{
				fout=new FileOutputStream(fname);	
			}catch(FileNotFoundException e){
				System.out.println(e);
				return;
			}
			try{
				fout.write(new String(convOutput.getText()).getBytes());
			}catch(IOException e){
				System.out.println(e);
				return;
			}
			try{
				fout.close();
			}catch(IOException e){
				System.out.println(e);
			}
		}
	}
}

I work out further in this matter, I tried the above code but in above code when user send the message, his window minimizes but what i want to do to blink the title bar or maximize the window on top automatically or anything which can attain user attention.
Help plzzzzzz.
Anyone????
Thanks in advance

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.