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..............