Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with Java Instant Messenger

RobF11RobF11 Member Posts: 6
My friends and I are making this Java Instant Messenger right now, we're trying to make it so that you can have multiple sessions open up at once. I tried something, but it wouldn't work. Any help would be appreciated.

heres the code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.applet.*;
import javax.*;
import java.lang.*;
import java.util.*;

public class JIM extends JPanel implements ActionListener{
JTextField serverInput, radioButtons, name;
JMenuBar menuBar;
JTextArea cousinIt;
String myIP;
int sendPort, receivePort;
JScrollPane tim;
SoundList soundList;
JMenu menu;
JMenuItem menuItem;
byte[] data;
JLabel label;
JFrame newFrame;
JFrame frame;
URL codeBase;
JButton voteButton;
DatagramSocket socket;
DatagramPacket packet;
ArrayList conversation;
JPanel button, box, pane, bottomPanel;
JLabel title;
InetAddress destination;
JIM hippo;
Container contentPane;

public static void main(String[] args) {
int sendPort1 = Integer.parseInt(JOptionPane.showInputDialog(null, "What port # to send?", "1415"));
int receivePort1 = Integer.parseInt(JOptionPane.showInputDialog(null, "What port # to receive?", "1415"));
JFrame frame = new JFrame("JIM 3.2.5");
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1,1));
JIM hippo = new JIM(frame, sendPort1, receivePort1);
contentPane.add(hippo);
frame.pack();
frame.setVisible(true);
hippo.run();
}

public JIM(JFrame frame, int sPort, int rPort) {
data=new byte[1000000];
sendPort=sPort;
receivePort=rPort;
conversation = new ArrayList();
try {
socket = new DatagramSocket(sPort);
packet = new DatagramPacket(data, data.length);
}
catch(SocketException se) {
System.out.println("Unable to create Datagram Thread:" + se);
}
try {
codeBase = new URL("file:" + System.getProperty("user.dir") + "/");
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
}

this.frame = frame;

menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
menu = new JMenu("File");
menuBar.add(menu);
menuItem = new JMenuItem("new");
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
int sendPort1 = Integer.parseInt(JOptionPane.showInputDialog(null, "What port # to send?", "1416"));
int receivePort1 = Integer.parseInt(JOptionPane.showInputDialog(null, "What port # to receive?", "1416"));
JFrame frame = new JFrame("JIM 3.2.5");
Container contentPane = frame.getContentPane();
contentPane.setLayout(new GridLayout(1,1));
hippo = new JIM(frame, sendPort1, receivePort1);
contentPane.add(hippo);
frame.pack();
frame.setVisible(true);
hippo.run();
}
});
menu.add(menuItem);
menuItem = new JMenuItem("save");
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
int count=0;
String filename=JOptionPane.showInputDialog(null, "Input Filename");
EasyWriter outFile = new EasyWriter(filename);
if (outFile.bad())
{
System.err.println("Can't create "+filename+"
");
System.exit(1);
}
while(count=(received.indexOf(':')+8))
{
if(received.substring(received.indexOf(':')+2, received.indexOf(':')+8).equals("/popup"))
JOptionPane.showMessageDialog(null, received.replaceAll("/popup","").trim());
else
{
System.out.println(received.trim());
cousinIt.append("
"+received.trim());
cousinIt.setCaretPosition(cousinIt.getText().length());
}
}
else
{
System.out.println(received.trim());
cousinIt.append("
"+received.trim());
cousinIt.setCaretPosition(cousinIt.getText().length());
}
(soundList.getClip("imrcv.wav")).play();
}
}

Sign In or Register to comment.