.class vs .java

A .class file is a compiled .java file. .java is all text and is human readable. .class is binary (usually). You compile a java file into a class file by going to the command line, navigating to the .java file, and running javac “c:\the\path\to\your\file\yourFileName.java” You must have a java SDK installed on your computer (get … Read more

how to use a swing timer to start/stop animation

import javax.swing.Timer; Add an attribute; Timer timer; boolean b; // for starting and stoping animation Add the following code to frame’s constructor. timer = new Timer(100, new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { // change polygon data // … repaint(); } }); Override paint(Graphics g) and draw polygon from the data that was … Read more

How to establish a TCP Socket connection from a web browser (client side)?

I’ve read about WebSockets but they don’t seem to be pure “sockets”, because there is an application layer protocol over them. [Is the] websocket protocol so simple to implement that [it is] “almost”-sockets? Allowing regular socket connections directly from the browser is never going to happen because it opens up a huge risk. WebSockets is … Read more

Thread.Sleep() is freezing

Don’t ever call Thread.sleep(…) from within the Swing event thread as this will put the event thread itself to sleep. Since this thread is responsible for all Swing painting and user interaction, this will put your application to sleep. If all you want is a delay in the display, then consider use of a Swing … Read more

Applet not appearing full

Here’s another variation on your layout. Using @Andrew’s tag-in-source method, it’s easy to test from the command line: $ /usr/bin/appletviewer HomeApplet.java // <applet code=”HomeApplet” width=”400″ height=”200″></applet> import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class HomeApplet extends JApplet { @Override … Read more