Java applet using the Swing API

write a Java applet using the Swing API to manage a PC repair shop. When a PC is brought in for repair, a member of staff will use this applet to log it into the system as a repair job. They will also be able to use the applet to manage the job e.g. allocate a person to carry out the repair and enter costs.
You must not use a tool such as JBuilder to generate Java code. If you use code from elsewhere e.g. a text book, you must highlight the code and state the reference clearly and include a photocopy of the relevant pages from the text book or other source.
You should hard-code some initial data into your applet. You should not store any data in a file or database.
Level of functionality you should attempt to implement:
Level 1 � Your applet should:
a.     As a minimum, your program should store (in memory) at least 10 repair jobs. For each repair job, you need to store:
�     The name and phone number of the customer bringing the PC in for repair;
�     A brief textual description of the problem;
�     Whether the PC is under warranty or not.
b.     Your program must allocate and display a unique number for the job once it is accepted.
c.     The user must be able to view the details of jobs. They should be able to select either:
�     All the jobs in the system; or
�     Jobs being carried out under warranty.
Level 2 � Your applet must meet the requirements for level 1. In addition it should:
a.     You should carry out appropriate validation checks on input data e.g. the phone number contains all digits.
b.     System should cope with an unlimited number of jobs.
c.     The user should be able to select a job and then allocate a repairer to that job.
d.     The user should be able to display a list of jobs for each repairer.
Level 3 - Your applet must meet the requirements for level 1 and 2. In addition it should allow the user to:
a.     Select a job and input the cost of repair for:
�     the number of hours labour;
�     parts.
b.     Select a job and present the user with a cost for the labour (hard code an hourly labour cost) and parts, plus a total for that job. For jobs under warranty the total will be zero, however the cost of labour and parts will be shown.
c.     Be able to inform the business of the total expected income from the all the jobs in the system that are not under warranty.
Level 4 � Your applet must meet the requirements for level 1 to 3. In addition:
a.     The user should be able to enter a job priority which can be identified as high, medium or low.
b.     Each repairer should be able to view a list of their jobs in order of priority.

Done, what next ?
Noah

Similar Messages

  • JAVA & EXCEL using the POI API

    Hi,
    I presently have a stand alone application that I need to redesign for a future use of excel.
    I created a spreadsheet with the following cell value:
    B5 = 1st value
    B6 = second value
    B9 = final value
    B11 is the total : SUM(B5:B9)
    My code is:
    try {
    // Connect to the Excell workbook
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("testjava.xls"));
    HSSFWorkBook wb = new HSSFWorkbook(fs);
    // Choose the sheet object
    HSSFSheet sheet = wb.getSheetAt(0); // or use .getSheet("test");
    // Create the row object
    HSSFRow rowMonday = sheet.getRow(4);
    HSSFRow rowTuesday = sheet.getRow(5);
    HSSFRow rowWednesday = sheet.getRow(6);
    HSSFRow rowThursday = sheet.getRow(7);
    HSSFRow rowFriday = sheet.getRow(8);
    HSSFRow rowTotal = sheet.getRow(10);
    // Get the week value
    A5 = rowMonday.getCell((short)0);
    B5 = rowMonday.getCell((short)1);
    A6 = rowTuesday.getCell((short)0);
    B6 = rowTuesday.getCell((short)1);
    A7 = rowWednesday.getCell((short)0);
    B7 = rowWednesday.getCell((short)1);
    A8 = rowThursday.getCell((short)0);
    B8 = rowThursday.getCell((short)1);
    A9 = rowFriday.getCell((short)0);
    B9 = rowFriday.getCell((short)1);
    // Get the total value
    A11 = rowTotal.getCell((short)0);
    B11 = rowTotal.getCell((short)1);
    } catch ( IOException ex ) {
    ex.printStackTrace();
    System.out.println(ex);
    Here is my get method:
    public double getCellB11()
    this.dblTotal = this.B11.getNumericCellValue();
    return this.dblTotal;
    My application is a simple application with 7 JLabels and 7 JTextField and a getValue and a calculate JButton.
    the getValue button get the right value, the total is wrong it keep the value at the first run time.
    when I use the calculate button, the spreadsheet is updated with the new value, the total is right in the spreadsheet. But in my application the total still the same value at the first run time. It seems like if the value does not refresh itself.
    Here is the code fof the get and calculate methode in my application:
    if (object == butGetValue) {
    txtName.setText(ToExcel.getCellB3());
    txtMonday.setText(String.valueOf(ToExcel.getCellB5()));
    txtTuesday.setText(String.valueOf(ToExcel.getCellB6()));
    txtWednesday.setText(String.valueOf(ToExcel.getCellB7()));
    txtThursday.setText(String.valueOf(ToExcel.getCellB8()));
    txtFriday.setText(String.valueOf(ToExcel.getCellB9()));
    txtTotal.setText(String.valueOf(ToExcel.getCellB11()));
    if (object == butCalculate) {
    ToExcel.setCellB3(txtName.getText());
    ToExcel.setCellB5(Double.parseDouble(txtMonday.getText()));
    ToExcel.setCellB6(Double.parseDouble(txtTuesday.getText()));
    ToExcel.setCellB7(Double.parseDouble(txtWednesday.getText()));
    ToExcel.setCellB8(Double.parseDouble(txtThursday.getText()));
    ToExcel.setCellB9(Double.parseDouble(txtFriday.getText()));
    ToExcel.writeNewValue();
    txtTotal.setText(String.valueOf(ToExcell.getCellB11()));
    Is there anyone who can help me with this?
    Any help would be appreciate.

    That's native OS problem. Once excel opened a file(even for reading) you can't write to it using other program like your servlet. So close the file before writing, or simply write to different file name.

  • How to filter tasks on the Creation date using the IWorklist API in Java

    Hi all,
    I'm currently developing a java gui application to display usertasks set by the BPM.
    I use the WorkList API to communicate with the TaskActionActionHandler.
    I only want the tasks that has a creation that is after a specified date. Therefore I add a filter. The code for retrieving the usertasks now becomes:
    Map filterMap = new HashMap();
    SimpleDateFormat d = new SimpleDateFormat("dd-mm-yyyy");
    Date date = d.parse((String) dForm.get("filterdate"));
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    filterMap.put(IWorklistService.FILTER_TYPE_CREATE_DATE_FROM_FILTER,
    cal);
    RemoteWorklistServiceClient client = new RemoteWorklistServiceClient();
    client.init();
    IWorklistContext ctx = client.authenticateUser(user, password);
    List tasks = client.getWorklistTasks(ctx, filterMap,
    IWorklistService.SORT_FIELD_TASK_TITLE,
    IWorklistService.SORT_ORDER_ASCENDING);
    You can see from the above code-fragment that I specify a FILTER_TYPE_CREATE_DATE_FROM_FILTER filter that is given a Calendar object. This is not working properly. Also a Date value gives a runtime error.
    The error I get is :
    ORABPEL-10150 Worklist Service Task List Error. An error occured in the Worklist Service while retrieving the task list for user jcooper. Check the task filter criterion and the error stack and fix the cause of the error. Contact oracle support if error is not fixable. at com.evermind.server.rmi.RMIConnection.EXCEPTION_ORIGINATES_FROM_THE_REMOTE_SERVER(RMIConnection.java:1602) at com.evermind.server.rmi.RMIConnection.invokeMethod(RMIConnection.java:1553) at
    Can anyone tell me what kind of dateformat I have to specify for the filter option FILTER_TYPE_CREATE_DATE_FROM_FILTER?
    Thanks in advance!
    Tom

    Hi,
    Enter the format that you have defined in the configuration of the property in the Additional Metadata parameter. Use the syntax customFormat=<pattern>.
    In this link, you have at the end screenshots where to navigate in KM to see the property metadatas of your property:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/645d4357-0701-0010-07bd-a2ea8c4d0aaf
    Here see the Defenitions of the KM Metadata Properties:
    https://wiki.sdn.sap.com/wiki/display/KMC/DefenitionsoftheKMMetadata+Properties
    Regards,
    Praveen Gudapati

  • How to use the Worklist API from Java (classpath ??)

    Hi all,
    Sorry for a novice question but I couldn't find the way to go about this (probably because it's such common knowldge...)
    I would like to try and use the Worklist API from my Java code in Eclipse, and according to the BPEL dev-guide I need to add an Import command for oracle.tip.pc.api.worklist. Where do I find these classes ?????
    I guess I need to change my CLASSPATH but I couldn't find a single word about this in the BPEL dev-guide (chapter 17), BPEL installation guide or elseware.
    thanks.

    Hi all,
    Ok now.
    To summarize - I was trying the code from BPEL developer guide, chapter 17, page 40 for using the Worklist local API's.
    Only after adding the following JAR's to the build path, was I able to compile it:
    orabpel-common.jar
    orabpel.jar
    bpm-infra.jar
    bpm-services.jar
    So, these 4 JAR's are required for using the Worklist local API's (not a clue in the dev guide itself for this requirement though...)
    Thank you very much for your help,
    assaf.

  • Using the Desktop API in Java SE 6 (Mustang)

    <p>The Java platform continues to evolve, and Java applications can now integrate with the host desktop better than ever before. This new article describes how to integrate your Java application into the desktop using new Java SE 6 features:</p>
    http://java.sun.com/developer/technicalArticles/J2SE/Desktop/mustang/desktop_api/

    peterwkc wrote:
    Hello to all,
    this is some sort of theoretical question.
    I been reading the JMS documentation for a while.
    1.I could not understand what this statement means :
    >
    This section describes the ways in which using the JMS API in enterprise bean applications or web applications differs from using it in application clients.
    What a developer is allowed to do is different depending on whether they are writing code to run in a container or not. The container already provides lots of services so some code you would write for outside a container is not needed when you write for a container. There are APIs that you are not allowed for in container code if you want to adhere to the spec.
    >
    2. What is the difference to use the JMS in java EE web orEJB container and application client ?
    Thanks.Read more of that document to find out the differences. Application components in Web/EJBs must not create more than one active session per connection while application clients are allowed to do so.

  • Using the JMS API in Java EE Applications

    Hello to all,
    this is some sort of theoretical question.
    I been reading the JMS documentation for a while.
    1.I could not understand what this statement means :
    >
    This section describes the ways in which using the JMS API in enterprise bean applications or web applications differs from using it in application clients.
    2. What is the difference to use the JMS in java EE web orEJB container and application client ?
    Thanks.

    peterwkc wrote:
    Hello to all,
    this is some sort of theoretical question.
    I been reading the JMS documentation for a while.
    1.I could not understand what this statement means :
    >
    This section describes the ways in which using the JMS API in enterprise bean applications or web applications differs from using it in application clients.
    What a developer is allowed to do is different depending on whether they are writing code to run in a container or not. The container already provides lots of services so some code you would write for outside a container is not needed when you write for a container. There are APIs that you are not allowed for in container code if you want to adhere to the spec.
    >
    2. What is the difference to use the JMS in java EE web orEJB container and application client ?
    Thanks.Read more of that document to find out the differences. Application components in Web/EJBs must not create more than one active session per connection while application clients are allowed to do so.

  • Problems while uploading files using the FileReference API

    I've built an image uploader module in Flex using the FileReference API and PHP.
    While this works perfect for images upto 1 MB, What I'm noticing is that for images greater that 1 MB even after the Event.COMPLETE  has triggered, the file hasn't yet been uploaded into the folder.. its only after a couple of seconds or minutes after the Event.COMPLETE,  that the image actually shows up in the FTP folder. Morever I also noticed that for such files the DataEvent.UPLOAD_COMPLETE_DATA that we are using to get feedback from PHP never gets called.
    I thought it would be related to the PHP script getting timed out... but the PHP script does get executed and the images do show up in the folder but thats way after the Event.Complete has been triggered and more importantly  DataEvent.UPLOAD_COMPLETE_DATA doesnt get called.
    Everything seems to work fine as long as the file size is under 1 MB
    Did others too face similar problems and any ideas on how to fix it?
    Thanks in advance

    I don't believe there is, as the browse button renders out as an html input type file component, and this has no ability to get native file size from the client. The only way to do it is to check the file size server side, but that kind of defeats the purpose to some extent, as the file is required to be uploaded before the file size can be checked.
    There is no way to do this on the client short of using a third party client side component - ie. java, flash or some other active component that gets file system level access.
    Ben

  • How to count number of lines inside methods() using the Doclet API

    Wrote a custom doclet using the [Doclet API|http://java.sun.com/j2se/1.3/docs/tooldocs/javadoc/doclet/index.html ] .
    The purpose for the doclet is to load Java source files and create stubs (which are identical Java source files but do not contain any method implementation details).
    Instead, the method implementation details need to be replaced with blank lines...
    public class MyDoclet {
         private static String TAB = "\t";
         public static boolean start(RootDoc root) {
              ClassDoc[] classes = root.classes();
              // Parse through class or interface
              for (ClassDoc clazz : classes) {
                   Type superClass = clazz.superclassType();     
                   // Print Methods
                   MethodDoc[] methods = clazz.methods();
                   for (MethodDoc method : methods) {
                        Parameter[] parameters = method.parameters();
                        println();
                        if (!method.isPrivate()) {
                             print(TAB + method.modifiers() + " "
                                                    + method.returnType().simpleTypeName() + " " + method.name());
                             print("(");
                             for (int i=0; i < parameters.length; i++) {
                                  Parameter parameter = (Parameter) parameters;
                                  print(parameter.type().simpleTypeName() + " " + parameter.name());
                                  if (i != parameters.length - 1) {
                                       print(", ");
                             print(")");
                             println(" {");
                             println("\n");
                             println(TAB + "}");
              return true;
    As one can see, I am just creating the method and placing the opening and closing curly braces (along with a new \n line escape sequence, in between).
    Am not really that familiar with the Doclet API...
    Question(s):
    (1) What is the best way to figure out how many lines of code are inside each method and then use a for loop to insert the exact same number of blank lines inside the methods?
    (2) Is there a way to do it using the com.sun.javadoc.SourcePosition.line() method?
    Would really appreciate it if someone could help me because this is an important requirement (hence the 10 Duke Stars).
    Happy coding to all,
    Mike                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    This is not possible using the Doclet API, because JavaDoc does not store any information regarding implementation detail. Although MethodDoc#position will give you the line where the method is declared, there is no way to determine where the method body starts and ends.
    If you need that much information, maybe you would be better of using a tool such as Eclipse's Abstract Syntax Tree parser. AST will provide you with line numbers for each code expression, hence it is relatively easy to compute the first and last line in a method body.

  • Using the swing clipboard and DefaultEditorKit.copytAction

    Hi all
    Ive heard that i can use the swing DefaultEditorKit to basically copy and paste text throughout my application (like using Ctrl+C ctrl+V)
    basically i have a number of elements such as textpanes and edit boxes and i want to be able to copy and paste text between them with the least amount of effort, most examples i have seen about implementing copy and paste require you to specify the elements that you need to copy and paste from
    i dont want to have to specify every element, i just want a simple action that says copy the selected text, and paste the selected text (dont have to worry about cut really)
    Ctrl+C and Ctrl+V both do this natrually, but how do i call a simple method that does the same thing that the keystrokes do.
    I just want two menu items that when i invoke their click listeenrs to say something like
    copylistener{
    copy();
    Ive seen a few examples of the swing methods but these also seem to need to invoke actions on the elements that you want to copy and paste between, but the keystroke dont need any of this

    Sorry, I see your confusion now.
    Yes, you need a few helper methods to get the actual Action, but you don't need to do this for every text component because the Action is shared by all text components.
    Text components use an EditorKit. The editor kit provides support for basic functionality of each text component. (ie. cursor movement, text selection, cut, copy, paste...). The EditorKit uses Actions to implement the basic support. Each Action extends TextAction which contains a method "getFocusedComponent" which returns the last text component that currently has focus. (clicking on a menu item is only a temporary loss of focus).
    So the code in the TextComponentDemo is being very efficient and is reusing the static Action that was created by the DefaultEditorKit. So even though your form may have multiple text components, you only need to create your menu item once using any text component.
    If you don't want your code to reuse the existing Actions, you can create your own Action directly from the EditorKit. Then this Action can be used to create a JMenuItem or JButton. Here is a simple example of using this approach:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=302962

  • Please give me an exemple of an applet using a swing object.

    Please give me an exemple of an applet using a swing object.thank you.

    My problen is that the swing object do not appear in
    my applet. They appear only if i invoque the repaint
    methode.use JApplet, since awt components are heavyweight, and swing components are lightwieght, then your swing components get over painted with aplets background or something.
    anyhow, in your applet you may create JFrame, that would be swing component and if you set it visible, then it will be even visible.
    they say that mixing swing and awt is not good idea, especially when you don't know what you're doing (which might be true in your case)
    so try to migrate your app from AWT based stuff to SWING based stuff, or write your own AWT components that do the job whih you needed swing component for at the first place.
    but if you need to mix awt and swing, then i thing that you should not paint the fole area of applet in applets paint method -- but here i'm not sure, never mixed 'em.
    so you might try to create an applet which paint() method you leave empty and to which you add some JComponent*.
    and see what happens, maybe this JComponent will be visible.
    * -- JComponent is most likely just gray, you might want to add some subclass of it -- JButton, JTextField, JSomethingElse.

  • Chat Applet using RMI .... trouble running the Applet using the IE browser.

    Hi,
    I'm trying to run a chat application using RMI technology. Actually, this wasn't created from the scratch. I got this one from from the cd that comes with the book I bought and I did some refinements on it to suit what I wanted to:
    These are the components of the chat application:
    1. RApplet.html - invokes the applet
    html>
    <head>
    <title>Sample Applet Using Dialog Box (1.0.2) - example 1</title>
    </head>
    <body>
    <h1>The Sample Applet</h1>
    <applet code="RApplet.class" width=460 height=160>
    </applet>
    </body>
    </html>
    2. RApplet.java - Chat session client applet.
    import java.rmi.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.rmi.server.*;
    //import ajp.rmi.*;
    public class RApplet extends Applet implements ActionListener {
    // The buttons
    Button sendButton;
    Button quitButton;
    Button startButton;
    Button clearButton;
    // The Text fields
    TextField nameField;
    TextArea typeArea;
    // The dialog for entering your name
    Dialog nameDialog;
    // The name the server knows us as
    String privateName;
    // The name we want to be known as in the chat session
    String publicName;
    // The remote chats erver
    ChatServer chatServer;
    // The ChatCallback
    ChatCallbackImplementation cCallback;
    // The main Chat window and its panels
    Frame mainFrame;
    Panel center;
    Panel south;
    public void init() {
    // Create class that implements ChatCallback.
    cCallback = new ChatCallbackImplementation();
         // Create the main Chat frame.
         mainFrame = new Frame("Chat Server on : " +
                        getCodeBase().getHost());
         mainFrame.setSize(new Dimension(600, 600));
         cCallback.displayArea = new TextArea();
         cCallback.displayArea.setEditable(false);
         typeArea = new TextArea();
         sendButton = new Button("Send");
         quitButton = new Button("Quit");
         clearButton = new Button("Clear");
         // Add the applet as a listener to the button events.
         clearButton.addActionListener(this);
         sendButton.addActionListener(this);
         quitButton.addActionListener(this);
         center = new Panel();
         center.setLayout(new GridLayout(2, 1));
         center.add(cCallback.displayArea);
         center.add(typeArea);
         south = new Panel();
         south.setLayout(new GridLayout(1, 3));
         south.add(sendButton);
         south.add(quitButton);
         south.add(clearButton);
         mainFrame.add("Center", center);
         mainFrame.add("South", south);
         center.setEnabled(false);
         south.setEnabled(false);
         mainFrame.show();
         // Create the login dialog.
         nameDialog = new Dialog(mainFrame, "Enter Name to Logon: ");
         startButton = new Button("Logon");
         startButton.addActionListener(this);
         nameField = new TextField();
         nameDialog.add("Center", nameField);
         nameDialog.add("South", startButton);
         try {
         // Export ourselves as a ChatCallback to the server.
         UnicastRemoteObject.exportObject(cCallback);
         // Get the remote handle to the server.
         chatServer = (ChatServer)Naming.lookup("//" + "WW7203052W2K" +
                                  "/ChatServer");
         catch(Exception e) {
         e.printStackTrace();
         nameDialog.setSize(new Dimension(200, 200));
         nameDialog.show();
    * Handle the button events.
    public void actionPerformed(ActionEvent e) {
         if (e.getSource().equals(startButton)) {
         try {
              nameDialog.setVisible(false);;
              publicName = nameField.getText();
              privateName = chatServer.register(cCallback, publicName);
              center.setEnabled(true);
              south.setEnabled(true);
              cCallback.displayArea.setText("Connected to chat server as: " +
                             publicName);
              chatServer.sendMessage(privateName, publicName +
                             " just connected to server");
         catch(Exception ex) {
              ex.printStackTrace();
         else if (e.getSource().equals(quitButton)) {
         try {
              cCallback.displayArea.setText("");
              typeArea.setText("");
              center.setEnabled(false);
              south.setEnabled(false);
              chatServer.unregister(privateName);
              nameDialog.show();
         catch(Exception ex) {
              ex.printStackTrace();
         else if (e.getSource().equals(sendButton)) {
         try{
              chatServer.sendMessage(privateName, typeArea.getText());
              typeArea.setText("");
         catch(Exception ex) {
              ex.printStackTrace();
         else if (e.getSource().equals(clearButton)) {
         cCallback.displayArea.setText("");
    public void destroy() {
         try {
         super.destroy();
         mainFrame.setVisible(false);;
         mainFrame.dispose();
         chatServer.unregister(privateName);
         catch(Exception e) {
         e.printStackTrace();
    3. Chatcallback.java - interface used by clients to connect to the server.
    import java.rmi.*;
    public interface ChatCallback extends Remote {
    public void addMessage(String publicName,
                   String message) throws RemoteException;
    4. ChatcallbackImplementation.java - implements Chatcallback interface.
    import java.rmi.*;
    import java.io.*;
    import java.awt.event.*;
    import java.awt.*;
    public class ChatCallbackImplementation implements ChatCallback {
    // The buttons
    // The Text fields
    TextArea displayArea;
    public void addMessage(String publicName,
                   String message) throws RemoteException {
    displayArea.append("\n" + "[" + publicName + "]: " + message);
    5. Chatserver.java - interface for the chat server.
    import java.rmi.*;
    import java.io.*;
    public interface ChatServer extends Remote {
    public String register(ChatCallback object,
                   String publicName) throws RemoteException;
    * Remove the client associated with the specified registration string.
    * @param registeredString the string returned to the client upon registration.
    public void unregister(String registeredString) throws RemoteException;
    * The client is sending new data to the server.
    * @param assignedName the string returned to the client upon registration.
    * @param data the chat data.
    public void sendMessage(String registeredString, String message) throws RemoteException;
    6. ChatServerImplementation.java - implements Chatserver interface.
    import java.rmi.*;
    import java.util.*;
    import java.rmi.server.*;
    import java.io.*;
    * A class that bundles the ChatCallback reference with a public name used
    * by the client.
    class ChatClient {
    private ChatCallback callback;
    private String publicName;
    ChatClient(ChatCallback cbk, String name) {
         callback = cbk;
         publicName = name;
    // returns the name.
    String getName() {
         return publicName;
    // returns a reference to the callback object.
    ChatCallback getCallback() {
         return callback;
    public class ChatServerImplementation extends UnicastRemoteObject
    implements ChatServer {
    // The table of clients connected to the server.
    Hashtable clients;
    // Tne number of current connections to the server.
    private int currentConnections;
    // The maximum number of connections to the server.
    private int maxConnections;
    // The output stream to write messages to.
    PrintWriter writer;
    * Create a ChatServer.
    * @param maxConnections the total number if connections allowed.
    public ChatServerImplementation(int maxConnections) throws RemoteException {
         clients = new Hashtable(maxConnections);
         this.maxConnections = maxConnections;
    * Increment the counter keeping track of the number of connections.
    synchronized boolean incrementConnections() {
         boolean ret = false;
         if (currentConnections < maxConnections) {
         currentConnections++;
         ret = true;
         return ret;
    * Decrement the counter keeping track of the number of connections.
    synchronized void decrementConnections() {
         if (currentConnections > 0) {
         currentConnections--;
    * Register with the ChatServer, with a String that publicly identifies
    * the chat client. A String that acts as a "magic cookie" is returned
    * and is sent by the client on future remote method calls as a way of
    * authenticating the client request.
    * @param object The ChatCallback object to be used for updates.
    * @param publicName The String the object would like to be known as.
    * @return The actual String assigned to the object for removing, etc. or
    * null if the client could not register.
    public synchronized String register(ChatCallback object, String publicString) throws RemoteException {
         String assignedName = null;
         if (incrementConnections()) {
         ChatClient client = new ChatClient(object, publicString);
         assignedName = "" + client.hashCode();
         clients.put(assignedName, client);
         out("Added callback for: " + client.getName());
         return assignedName;
    * Remove the client associated with the specified registration string.
    * @param registeredString the string returned to the client upon registration.
    public synchronized void unregister(String registeredString) throws RemoteException {
         ChatCallback cbk;
         ChatClient sender;
         if (clients.containsKey(registeredString)) {
         ChatClient c = (ChatClient)clients.remove(registeredString);
         decrementConnections();
         out("Removed callback for: " + c.getName());
         for (Enumeration e = clients.elements(); e.hasMoreElements(); ) {
              cbk = ((ChatClient)e.nextElement()).getCallback();
              cbk.addMessage("ChatServer",
                        c.getName() + " has left the building...");
         else {
         out("Illegal attempt at removing callback (" + registeredString + ")");
    * Sets the logging stream.
    * @param out the stream to log messages to.
    protected void setLogStream(Writer out) throws RemoteException {
         writer = new PrintWriter(out);
    * The client is sending new message to the server.
    * @param assignedName the string returned to the client upon registration.
    * @param data the chat data.
    public synchronized void sendMessage(String registeredString, String message) throws RemoteException {
         ChatCallback cbk;
         ChatClient sender;
         try {
         out("Recieved from " + registeredString);
         out("Message: " + message);
         if (clients.containsKey(registeredString)) {
              sender = (ChatClient)clients.get(registeredString);
              for (Enumeration e = clients.elements(); e.hasMoreElements(); ) {
                   cbk = ((ChatClient)e.nextElement()).getCallback();
                   cbk.addMessage(sender.getName(), message);
         else {
              out("Client " + registeredString+ " not registered");
         catch(Exception ex){
         out("Exception thrown in newData: " + ex);
         ex.printStackTrace(writer);
         writer.flush();
    * Write s string to the current logging stream.
    * @param message the string to log.
    protected void out(String message){
         if(writer != null){
         writer.println(message);
         writer.flush();
    * Start up the Chat server.
    public static void main(String args[]) throws Exception {
         try {
         // Create the security manager
         System.setSecurityManager(new RMISecurityManager());
         // Instantiate a server
         ChatServerImplementation c = new ChatServerImplementation(10);
         // Set the output stream of the server to System.out
         c.setLogStream(new OutputStreamWriter(System.out));
         // Bind the server's name in the registry
         Naming.rebind("//" + args[0] + "/ChatServer", c);
         c.out("Bound in registry.");
         catch (Exception e) {
         System.out.println("ChatServerImplementation error:" +
                        e.getMessage());
         e.printStackTrace();
    Using my own machine (connected to a network), I tried to test this one out by setting mine as the server and also the client. I did the following:
    1. Compile the source code.
    2. Use rmic to generate the skeletons and/or stubs from the ChatCallbackImplementation and ChatServerImplementation.
    3. Start the rmiregistry with no CLASSPATH
    4. Start the server successfully.
    5. Start the applet using the AppletViewer command.
    It worked fined.
    The problem is when I ran the applet using the browser, IE explorer, the dialog boxes, frame and buttons did appear. I was able to do the part of logging on. But after that, the applet seemed to have hang. No message appeared that says I'm connected (which appeared using the appletviewer). I clicked the send button. No response.
    I double-checked my classpath. I did have my classpath set correctly. I'm still trying to figure out the problem. Up to now, I don't have any clue what it is.
    I will appreciate much if someone can help me figure what's could have possibly been wrong ....
    Thanks a lot ...

    Hi Domingo,
    I had a similar problem running applet/rmi with IE.
    Looking in IE..view..JavaConsole error messages my applet was unable to find java.rmi.* classes.
    I checked over java classes in msJVM, they're not present.
    ( WinZip C:\WINDOWS\JAVA\Packages\9rl3f9ft.zip and others from msVM installed )
    ( do not contain the java.rmi.* packages )
    I have downloaded and installed the latest msJVM for IE5. ( I think its included in later versions)
    @http://www.objectweb.org/rmijdbc/RJfaq.html I found ref to rmi.zip download to provide
    these classes. I couldn't get the classes from the site but I managed to find a ref to IBM
    site @http://alphaworks.ibm.com/aw.nsf/download/rmi which had similar download.
    The download however didn't solve my problems. I was unable to install rmi.zip with
    RmiPatch.exe install.
    I solved this by extracting the class files from rmi.zip and installing them at C:\WINDOWS\JAVA\trustlib ( msJVM installation trusted classes lib defined in
    registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Java VM\TrustedLibsDirectory )
    This solved the problem. My rmi/applet worked.
    Hope this helps you.
    Chris
    ([email protected])

  • Displaying java applet using webseal authentication

    Hi all,
    i'm facing a problem about displaying Java applet using Webseal junction for accessing  an application Server based on Websphere.
    I've defined a webseal ACL on accessing a http url that contains link to Java applet: after webseal authentication, the homepage is loaded; in the home page are presented links to java applet, but when I try to load these applets, it seems not working.
    If I load the same applets without Webseal authentication, it seems working.
    Is there any sort of configuration to make for applet regarding Webseal?
    Thanks in advance
    Danilo

    Hi all,
    i'm facing a problem about displaying Java applet using Webseal junction for accessing  an application Server based on Websphere.
    I've defined a webseal ACL on accessing a http url that contains link to Java applet: after webseal authentication, the homepage is loaded; in the home page are presented links to java applet, but when I try to load these applets, it seems not working.
    If I load the same applets without Webseal authentication, it seems working.
    Is there any sort of configuration to make for applet regarding Webseal?
    Thanks in advance
    Danilo

  • Creating junit test cases using the reflection API

    In order to use the reflection API to get information about a *.java file's class name and methods, I need to compile the *.java file first, and then get info through the *.class file. Am I right?
    Eclipse, the Java IDE, can create junit test cases for java files the user selects right after the *.java files have been created, and even before the *.java files have been compiled by the user. I guess Eclipse internally compiles the java files before creating JUnit test cases for them. Does anyone know about it? Thanks.

    Let me explain my problem in more details.
    Given any java source tree, my program is supposed to create junit test cases for each class using java reflection. My approach is to scan through the source tree to keep the list of classes available, then compile all the java files in the given source tree, then do Class.forName() to load them to get their methods... Obviously I don't know what classes I will have at compilation time. I create a temp_classes directory as the output directory for the given source tree java files, and I add temp_classes to my classpath when I strart up my own program. However, that won't work..
    D:\eclipse\workspace\cmpe271_hw4\classes>java -classpath ..\classes;..\temp_classes Test
    javac -classpath .\temp_classes; -d .\temp_classes @temp_classes\javalist.txt
    java.lang.ClassNotFoundException: Factory
    java.lang.ClassNotFoundException: InvalidDateFormatException
    java.lang.ClassNotFoundException: MyUtility
    java.lang.ClassNotFoundException: Storage

  • Change workarea rule using the Repository API

    Hi,
    I have a simple question: Can I use the Repository API (either
    Java or PLSQL packages) to change the rule of workarea: in order
    to add to or remove configurations from the rule? I do not want
    the use the RON and preferably not the CLT either.
    I could not find anything about this functionality in the API
    doc.
    Regards,
    Rinse Veltman
    Solution Partners
    Custom Solutions

    Rinse,
    Have a look at the API jr_workarea
    FUNCTION jr_workarea.add_head_entry (workarea_id IN NUMBER
    , entry_ivid IN NUMBER
    , rule_id IN NUMBER:=NULL
    , v_param1 IN VARCHAR2:=NULL
    , v_param2 IN VARCHAR2:=NULL
    , v_param3 IN VARCHAR2:=NULL
    , c_exclude IN CHAR:=NULL)
    RETURN NUMBER;
    Where:
    workarea_id specifies the workarea.
    entry_ivid is the IVID of the configuration, if the entry is
    associated with a configuration, NULL otherwise.
    rule_id is the IRID of the rule to be used, if the entry is
    associated with a rule, NULL if the entry is configuration based.
    param1 through v_param3 are parameter values (if any) for the
    rule.
    c_exclude specifies whether to exclude or include objects
    produced by the rule or contained in the configuration.
    Use entry_ivid to specify a configuration. This is in the Model
    and API documentation.
    regards,
    David

  • Using the Preferences API

    I've never used this API before, so excuse my ignorance. I have a web application that I have been using a properties file to store base app info, such as the backend database, the url for the ldap, etc. This has been working fine, but after reading about the Preferences API, I thought that this might be the better place to store this info. However, I'm having permission problems that I haven't been able to figure out.
    I've got a development copy of everything on a single computer (using Windows XP), Sun One App Server, and Oracle.
    I created a small test class to see if I could load preferences from an xml file. Here's the class
    package portal.common;
    import java.util.*;
    import java.util.prefs.*;
    import java.io.*;
    import java.lang.*;
    public class PortalPreferences{
         Preferences sysPreferencesRoot;
         public void prefs() throws SecurityException{
    sysPreferencesRoot = Preferences.systemRoot();
         public void uploadPrefs(String file) throws IOException, InvalidPreferencesFormatException{
         FileInputStream fis = new FileInputStream(file);
         RuntimePermission rpermiss = new RuntimePermission("preferences.*");
         Preferences.importPreferences(fis);
         public Preferences getPrefs(){
         return sysPreferencesRoot;
    I then used a jsp to instantiate the class and call the uploadPrefs method. The class instantiates without error, but when I try to load the xml file I get the following error:
    access denied (java.lang.RuntimePermission preferences)
    I've never done anything with the security manager before so I'm not sure how to get around this. I tried creating a RuntimePermission object above, but that didn't work.
    If anyone has any ideas, I'd much appreciate it.

    No, actually I've got the Sun One App server loaded on a desktop I built that I'm using as a test box - its not a server. The Sun server is running fine, as is Oracle. The only problem I'm having is figuring out how to use the Preferences API. Maybe this API isn't the right thing to be using, that's why I'm asking for advice as well as how to get around the security issue that I'm having. My goal is to have application level information that can be stored somewhere other than in a database - this is because one of the pieces of app info is the database that's being used. This app will work with any backend. Currently, this info is stored in a properties file inside the WEB-INF directory. This works fine as is. However, my issue with that is that in order to load the properties file, I've got to have a real drive path. This again isn't that much of an issue except when trying to access from a class that doesn't have the servlet context, however, I am looking for an alternative solution to the properties file. The Preferences seemed like a good solution.

Maybe you are looking for

  • How to manipulate Informix's collection columns in JDBC ?

    Howdy, Please does anyone have any examples of how to use informix's collection columns via JDBC? (I'm specifically interested in list) IBM (the worlds third? largest computer company) has the worst website on the planet. It's near impossible to find

  • How to view of damaged lotus notes nsf file?

    After the restoration of utilities through almost all the bases when opening throw an error "File is not database", "File does not exist" or "Database is corrupt - Can not allocate space". How to view of damaged lotus notes nsf file?

  • Photoshop 7.4 Update

    What needs to be done to resolve Photoshop Camera Raw 7.4 update error message U43M1D207

  • Activation error in AME CS6 on Mac

    I have four user IDs on my Mac: my everyday user account, another account for my wife, a guest account, and a root account. Today I was using AME in my regular account and it worked fine. Then I switched by my wife's account (I quit AME in the regula

  • I got error -50 on iMovie. Anyone had the same?  HELP PLEASE SOS!

    I cannot publish my videos, neither save them on file. iMovie gave an erro -50. I ran Disk Utilities and shows tha everything is running fine. What can I do to repair this error? Please helo! thanks!