Results 1 to 6 of 6
- 09-09-2009, 06:58 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
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:
Any and all help is appreciated! Thank you!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; } }
- 09-09-2009, 07:28 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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 ...
- 09-10-2009, 02:50 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
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.
- 09-10-2009, 08:40 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 09-10-2009, 06:44 PM #5
Member
- Join Date
- Sep 2009
- Posts
- 3
- Rep Power
- 0
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.
- 09-10-2009, 09:23 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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
-
[newbie] Rectangle2D not drawn within applet
By jon80 in forum New To JavaReplies: 7Last Post: 06-06-2009, 09:43 PM -
[SOLVED] [newbie] running an applet ??
By jon80 in forum New To JavaReplies: 4Last Post: 05-31-2009, 09:42 PM -
Calling another applet on click of button in one applet
By niteshwar.bhardwaj in forum Java 2DReplies: 1Last Post: 02-19-2009, 12:54 PM -
Newbie in applet, Help me
By barney in forum Java AppletsReplies: 1Last Post: 08-07-2007, 07:14 AM -
Applet, To center text and To open I engage in a dialog in an Applet
By Marcus in forum Java AppletsReplies: 4Last Post: 06-08-2007, 06:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks