Results 1 to 6 of 6
  1. #1
    tux633k is offline Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

    Default newbie needs help with an applet please

    I'm new to java and also to this forum so hopefully I'm posting this in the correct spot. I'm trying to create an applet which reacts similar to a queue, but I'm having a few issues so far and I might not be using the correct class perhaps etc.

    - When I add the ticket I need it to go into a timer mode so that after 2 hrs I will receive an email alert (I haven't added this portion of the code yet - just thought I'd give a breakdown)

    - I will also be adding another button to remove the ticket from the table.

    - At the moment it will add the ticket to the table (although I would also like it to add the priority of the ticket as well), but I haven't figured out how to do anything with it after this...

    My code is as follows, but I'm probably not headed in the right direction:

    Java Code:
    import java.applet.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class Queue extends JApplet 
                        implements ActionListener {
        private JTextField ticketField;
        private JTextArea q;
        private int counter;
    
        public void init() {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        createApplet();
                    }
                });
            } catch (Exception e) {
                System.err.println("The applet wasn't created successfully!");
            }
        }
    
        private void createApplet() {
            JPanel contentPane = new JPanel(new GridBagLayout());
            contentPane.setBorder(BorderFactory.createCompoundBorder(
                                        BorderFactory.createLineBorder(Color.RED),
                                        BorderFactory.createEmptyBorder(10,10,5,5)));
            setContentPane(contentPane);
            
            GridBagConstraints c = new GridBagConstraints();
            c.insets = new Insets(0,0,5,5);
    
            JLabel priorityLabel = new JLabel("Priority Code: ",
    					 JLabel.CENTER);
            add(priorityLabel, c);
    
            String[] data = {"1-3", "   4", "   9"};
            JList priorityCode = new JList(data);
            add(priorityCode, c);
    	
            JLabel ticketLabel = new JLabel("Enter Ticket#:", 
                                              JLabel.TRAILING);
            add(ticketLabel, c);
    
            ticketField = new JTextField(getParameter("TICKETNUMBER"),
                                                   10);
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 1.0;
            add(ticketField, c);
            ticketField.addActionListener(this);
    
            JButton button = new JButton("Add Ticket");
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.anchor = GridBagConstraints.LINE_START;
                                                     
            c.fill = GridBagConstraints.NONE;
                                             
            c.weightx = 0.0;
            add(button, c);
            button.addActionListener(this);
    
            q = new JTextArea(5, 60);
            q.setEditable(false);
            c.anchor = GridBagConstraints.CENTER;
            c.fill = GridBagConstraints.BOTH;
            c.weighty = 1.0;
            add(new JScrollPane(q), c);
    
    	counter = 0;
    
            JLabel status = new JLabel("(Total # of tickets in queue: " + counter + ")",
                                          JLabel.CENTER);
            c.weightx = 0.0;
            c.weighty = 0.0;
            add(status, c);
    
        }
    
        public void actionPerformed(ActionEvent event) {
    
            String TICKETNUMBER = ticketField.getText();
            q.append(TICKETNUMBER + "\n");
    	counter = counter + 1;
    
        }
    }
    Any and all help is appreciated! Thank you!

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    1.)Why does it have to be an applet? Why can't it be a normal Java application?
    2.) Why does Queue extend Applet?A queue is not an applet. Your applet should only be for display purposes.
    3.) What do you mean by add a ticket to a table? From your code you are appending String to a JTextField. That can hardly be described as adding a Ticket to a table. Do you want to add Tickets to a queue instead.
    Better redesign. Perhaps you need a Ticket class with it's own properties and then a Queue to add the tickets to e.t.c ...

  3. #3
    tux633k is offline Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

    Default

    1.)Why does it have to be an applet? Why can't it be a normal Java application?

    I would like to have other individuals within the dept add and remove from the queue via a webpage.

    2.) Why does Queue extend Applet?A queue is not an applet. Your applet should only be for display purposes.

    You're absolutely right, at the moment my queue is merely a name only since it is not using the appropriate class/structure, etc. I couldn't find a way to create a queue and then use it as an applet.

    3.) What do you mean by add a ticket to a table? From your code you are appending String to a JTextField. That can hardly be described as adding a Ticket to a table. Do you want to add Tickets to a queue instead.

    Yes, I want to add tickets to a queue.

    Better redesign. Perhaps you need a Ticket class with it's own properties and then a Queue to add the tickets to e.t.c ...

    Thanks for the suggestion... I need to read more into queues.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by tux633k View Post
    1.)..

    I would like to have other individuals within the dept add and remove from the queue via a webpage.

    ..
    If people are going to be adding to the queue from client machines via the web browser, where will the queue be stored so that it is shared? Are you going to use a database? Why not create a web application instead of an applet?

  5. #5
    tux633k is offline Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    0

    Default

    I was leaning towards an applet because I'm more familiar with regular java apps and applets since I took some Java classes years ago. I'll definately look into the web applications, but I was just going to try to keep this simple - 2 buttons (add and remove) and then just something to keep the ticket in a timer so that once it gets close to 2 hrs then it can send out an email. Thanks again. I'm not planning on keeping or storing the tickets in a database.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Don't let your knowledge alone decide what technologies need to be used to solve a problem. Consider other factors as well.
    You'll still need to decide to decide how to make the users add into the same queue. Applets running on the browser will have separate queues. You need a central server if you want to use one queue.

Similar Threads

  1. [newbie] Rectangle2D not drawn within applet
    By jon80 in forum New To Java
    Replies: 7
    Last Post: 06-06-2009, 10:43 PM
  2. [SOLVED] [newbie] running an applet ??
    By jon80 in forum New To Java
    Replies: 4
    Last Post: 05-31-2009, 10:42 PM
  3. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 01:54 PM
  4. Newbie in applet, Help me
    By barney in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 08:14 AM
  5. Replies: 4
    Last Post: 06-08-2007, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •