Category: Code . Programming Samples . প্রোগ্রাম উদাহরন

Code . Programming Samples . প্রোগ্রাম উদাহরন

BetterCircleTest.java

********************** BetterCircleTest.java ********************** import java.awt.*; import java.applet.Applet; /** Position circles down the diagonal so that their borders  *  just touch. Illustrates that Java 1.1 lightweight  *  components can be partially transparent.  *   */ public class BetterCircleTest extends Applet {   public void init() {     setBackground(Color.lightGray);     setLayout(null);     BetterCircle circle;     int radius …

Continue reading

RMI Example – Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration.

Integral.java  Performs actual numerical integration of the function (evaluatable object). /** A class to calculate summations and numeric integrals. The  *  integral is calculated according to the midpoint rule.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  …

Continue reading

A JPanel that displays six radio buttons with labels.

A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; /** A JPanel that displays six JRadioButtons.  *  *.  */ public class SixChoicePanel extends JPanel {   public SixChoicePanel(String title, String[] buttonLabels) {     super(new GridLayout(3, 2));     setBackground(Color.lightGray);     setBorder(BorderFactory.createTitledBorder(title));     ButtonGroup group = new ButtonGroup();     JRadioButton option;     int …

Continue reading

ThreadedEchoServer.java A multithreaded version of EchoServer, where each client request is serviced on a separate thread. Requires the following classes

import java.net.*; import java.io.*; /** A multithreaded variation of EchoServer.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  may be freely used or adapted.  */ public class ThreadedEchoServer extends EchoServer                                 implements Runnable {   public static …

Continue reading

Implementing a Server : Network Server

NetworkServerTest.java  Establishes a network Server that listens for client requests on the port specified (command-line argument). Uses the following classes:   /** Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  may be freely used or adapted.  */ public class …

Continue reading

UrlTest.java Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.)

জা import java.net.*; /** Read a URL from the command line, then print  *  the various components.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  may be freely used or adapted.  */ public class UrlTest {   …

Continue reading

Counter2Test.java Driver class that creates three threaded objects (Counter2) that count from 0 to 4.

/** Try out a few instances of the Counter2 class. Driver class that creates three threaded objects (Counter2) that count from 0 to 4. In this case, the driver does not start the threads, as each thread is automatically started in Counter2’s constructor. Uses the following class: Counter2Test.java Counter2.java **************************     public class Counter2Test { …

Continue reading

Template illustrating the first approach for creating a class with thread behavior.

** Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,   *  © 2001 Marty Hall and Larry Brown;  *  may be freely used or adapted.  */ public class ThreadClass extends Thread {  public void run() {    // Thread behavior here.   } }

Creates three radio buttons and illustrates handling

JRadioButtonTest.java Creates three radio buttons and illustrates handling ItemEvents in response to selecting a radio button. import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import java.awt.*; import java.awt.event.*; import javax.swing.*; /**  */ public class JRadioButtonTest extends JPanel                               implements ItemListener {   public JRadioButtonTest() {         String[] labels = {“Java Swing”,”Java Servlets”,                        “JavaServer Pages”};     JRadioButton[] …

Continue reading

Simple button that the user can select to load the entered URL.

JIconButton.java A simple button that the user can select to load the entered URL. import javax.swing.*; /** A regular JButton created with an ImageIcon and with borders  *  and content areas turned off.  *   */ public class JIconButton extends JButton {   public JIconButton(String file) {     super(new ImageIcon(file));     setContentAreaFilled(false);     setBorderPainted(false);     …

Continue reading