ChatFrame.java: Difference between revisions
Appearance
verwaist |
|||
Line 1: | Line 1: | ||
<PRE> | |||
import java.io.*; | |||
import java.awt.*; | |||
import java.awt.event.*; | |||
import java.applet.*; | |||
import java.net.*; | |||
import java.util.*; | |||
import javax.swing.*; | |||
public class ChatFrame extends JFrame | |||
implements AppletStub, | |||
AppletContext { | |||
private JApplet appletPane; | |||
public static void main(String[] args) { | |||
new ChatFrame(new ChatApplet()); | |||
} | |||
public ChatFrame(JApplet a) { | |||
appletPane = a; | |||
a.init(); | |||
a.setStub(this); | |||
addWindowListener(new WindowAdapter() { | |||
public void windowClosing(WindowEvent e) { | |||
doExit(); | |||
} | |||
}); | |||
setTitle("ChatClient"); | |||
Dimension size = new Dimension(640, 415); | |||
setSize(size); | |||
setResizable(false); | |||
Point location = new Point(0, 0); | |||
try { | |||
ObjectInputStream iniIn = | |||
new ObjectInputStream( | |||
new FileInputStream("chat.ini")); | |||
location = (Point)iniIn.readObject(); | |||
iniIn.close(); | |||
} catch (Exception e) { | |||
/* possibly no file, which is OK, or | |||
* corrupt which we don't bother with */ | |||
} | |||
setLocation(location); | |||
getContentPane().add(a); | |||
show(); | |||
a.start(); | |||
} | |||
private void doExit() { | |||
try { | |||
((ChatApplet)appletPane).disconnect(); | |||
ObjectOutputStream iniUt = | |||
new ObjectOutputStream( | |||
new FileOutputStream("chat.ini")); | |||
iniUt.writeObject(getLocationOnScreen()); | |||
iniUt.close(); | |||
} catch (Exception exc) {} // I don't care | |||
System.exit(0); | |||
} | |||
// The AppletStub methods | |||
public boolean isActive() {return true;} | |||
public URL getDocumentBase() {return null;} | |||
public URL getCodeBase() {return null;} | |||
public String getParameter(String name) {return ""; } | |||
public AppletContext getAppletContext() {return this;} | |||
public void appletResize(int w, int h) {} | |||
// The AppletContext methods | |||
public AudioClip getAudioClip(URL u) {return null;} | |||
public Image getImage(URL u) {return null;} | |||
public Applet getApplet(String name) {return null;} | |||
public Enumeration getApplets() {return null;} | |||
public void showDocument(URL u) {} | |||
public void showDocument(URL u, String s){} | |||
public void showStatus(String s) {} | |||
} | |||
</PRE> | |||
[[Category:Into Java]] |
Latest revision as of 19:11, 13 June 2020
import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; import java.util.*; import javax.swing.*; public class ChatFrame extends JFrame implements AppletStub, AppletContext { private JApplet appletPane; public static void main(String[] args) { new ChatFrame(new ChatApplet()); } public ChatFrame(JApplet a) { appletPane = a; a.init(); a.setStub(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { doExit(); } }); setTitle("ChatClient"); Dimension size = new Dimension(640, 415); setSize(size); setResizable(false); Point location = new Point(0, 0); try { ObjectInputStream iniIn = new ObjectInputStream( new FileInputStream("chat.ini")); location = (Point)iniIn.readObject(); iniIn.close(); } catch (Exception e) { /* possibly no file, which is OK, or * corrupt which we don't bother with */ } setLocation(location); getContentPane().add(a); show(); a.start(); } private void doExit() { try { ((ChatApplet)appletPane).disconnect(); ObjectOutputStream iniUt = new ObjectOutputStream( new FileOutputStream("chat.ini")); iniUt.writeObject(getLocationOnScreen()); iniUt.close(); } catch (Exception exc) {} // I don't care System.exit(0); } // The AppletStub methods public boolean isActive() {return true;} public URL getDocumentBase() {return null;} public URL getCodeBase() {return null;} public String getParameter(String name) {return ""; } public AppletContext getAppletContext() {return this;} public void appletResize(int w, int h) {} // The AppletContext methods public AudioClip getAudioClip(URL u) {return null;} public Image getImage(URL u) {return null;} public Applet getApplet(String name) {return null;} public Enumeration getApplets() {return null;} public void showDocument(URL u) {} public void showDocument(URL u, String s){} public void showStatus(String s) {} }