Controlling a label's text with Threads

Hello,
I couldn't find a specific topic about Java Threads and that's why i am writing here.
I am developing a kind of strategy game and in one module i need to show the total amount of money the user has.
- at first, when the game starts, the player chooses an amount.
- the game starts and the player buys something
- the amount should be updated, for a logical and routine transaction.
But since the frame which is responsible from such transactions differ from the main frame, i could not do the update operations.
e.g.
public class GameMain extends JFrame{
//The label is here
}//end of gamemain
class TransactionFrame extends JInternalFrame{
//The internal frame has some buttons and radio buttons to allow the user to make transactions, purchasing of certain tools
}//end of transactionframeThe best way that came into my mind was to update the label in my GameMain class whenever the player selects , say "Add" button in TransactionFrame.
I had many tests before to do it with a certain paint method to handle those issues, but i couldn't find a solution.
On the other hand, the TransactionFrame class' instances are created in some other class which I think wouldn't be relevant to say here, because it does nothing to do here.
What i want to do is, as defined above,
- i want to update the label in GameMain and
- it should be updated whenever "Add" button is clicked in the TransactionFrame, which is a JInternalFrame.
Here is what i have tried:
1. i added a flag value in the TransactionFrame's "Add" button, and whenever it becomes "true", the Thread controlling the Label's text of GameMain, is triggered
and the new amount will be presented to the user.
-->But, although the player doesn't click anything on the internal frame, the thread in the main frame consideres it as clicked and tries to run something else.
2. the other thing is, I put the amount at the internal frame as a string (drawn in paint method of this frame),
--> This time, I updated the amount here but whenever I close the frame and create the frame by clicking on some button, the amount remains as chosen in the starting phase.
(e.g. user selected 5000$, then bought something, the new amount: 4000$, ok, i close the frame and reopen it, the amount is: 5000$ !).
I hope that I described the problem clearly here,
What i expect is given above, if you'd like to advice me to try other things, please do not hesitate.
Thank you,
led1433

You're probably long gone, so I'm not sure you'll see this, but my opinion is that your next step is to try to decrease the cohesion (I think that's what it's called) of your code so that the code that represents your main GUI has little knowledge of the code that represents the JInternalFrame and visa versa. I'm no pro at this, but one way to possibly do this is to give both public methods that get and set the amount and then let a Controller class call these methods. For instance:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test3B {
  private static void createAndShowUI() {
    final Main3B main = new Main3B();
    main.getComponent().setPreferredSize(new Dimension(500, 400));
    final Internal3B internalGui = new Internal3B();
    internalGui.addSetAmountBtnListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        String amtString = internalGui.getAmountFieldText().trim();
        try {
          int amount = Integer.parseInt(amtString);
          main.setAmount(amount);
        } catch (NumberFormatException nfe) {
          JOptionPane.showMessageDialog(main.getComponent(), "Enter integers only",
              "Error", JOptionPane.ERROR_MESSAGE);
    JInternalFrame internalFrame = new JInternalFrame();
    internalFrame.getContentPane().add(internalGui.getMainPanel());
    internalFrame.setBounds(10, 10, 400, 300);
    internalFrame.setClosable(true);
    main.addInternalFrame(internalFrame);
    JFrame frame = new JFrame("Test3B");
    frame.getContentPane().add(main.getComponent());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        createAndShowUI();
class Main3B {
  private static final String AMOUNT_LABEL = "Amount is: ";
  private int amount = 0;
  private JPanel mainPanel = new JPanel();
  private JLabel amountLabel = new JLabel(AMOUNT_LABEL + amount, SwingConstants.LEFT);
  private JDesktopPane desktop = new JDesktopPane();
  public Main3B() {
    desktop.setBorder(BorderFactory.createLineBorder(Color.blue));
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(amountLabel, BorderLayout.NORTH);
    mainPanel.add(desktop, BorderLayout.CENTER);
  public void addInternalFrame(JInternalFrame internalFrame) {
    desktop.add(internalFrame);
    internalFrame.setVisible(true);
  public void setAmount(int amount) {
    this.amount = amount;
    amountLabel.setText(AMOUNT_LABEL + amount);
  public int getAmount() {
    return amount;
  public JComponent getComponent() {
    return mainPanel;
class Internal3B {
  private JPanel mainPanel = new JPanel();
  private JTextField amountField = new JTextField(10);
  private JButton setAmountBtn = new JButton("Set Amount");
  public Internal3B() {
    mainPanel.add(new JLabel("Enter New Amount:"));
    mainPanel.add(Box.createHorizontalStrut(5));
    mainPanel.add(amountField);
    mainPanel.add(Box.createHorizontalStrut(15));
    mainPanel.add(setAmountBtn);
  public JPanel getMainPanel() {
    return mainPanel;
  public String getAmountFieldText() {
    return amountField.getText();
  public void addSetAmountBtnListener(ActionListener al) {
    setAmountBtn.addActionListener(al);
}

Similar Messages

  • Any Nokia phones with Threaded Text messaging?

    I'm looking for a Nokia phone with threaded text messaging.
    Rather like the Palm Centro or Iphone:
    Anyone know of a basic model that can do it?
    I'm currently lusting after the Nokia 3720 Classic and would love if it could organise messages in a more useful way, and banish my thoughts of bulkier handsets. I've loved my Nokia 6030 for a few years but its disintergrating now. 

    s60 phones are usually the smartphone family the E and N series all run on s60. 
    6700 new navigator, the 6220c also runs on s60, 5800xm runs on the new gen for touch screens s60
    the lower modesl 1xxxxx,2xxxxx,3xxxx, 5xxxx,6xxx (the 6 family is divided and can either run on s40 or s60 depending on the phone) series usually run on s40 platform.  for every phone you can look up specs and it will tell you which platform or operating system the phone runs on 
    You know what I love about you the most, the fact that you are not me ! In love with technology and all that it can offer. Join me in discovery....

  • How to control a MacBook Pro remotely with ARD?

    I have ARD set up and installed, but I'm not sure how to set up a connection with the MBP so I can control and observe the MBP with ARD.
    Looking for a easy tutorial for a beginner in ARD.

    Hi apple is awesome,
    Just to check, you have one computer, with ARD installed, and your trying to use that computer to control your "BMP"?
    If so:
    On your BMP, you would want to setup sharing:
    go to the white menu bar at the top of the screen
    click on the Apple Menu
    chose "System Preferences..."
    when System Preferences opens, click the "Show All" button
    click on the "Sharing" icon
    if the lock in the bottom left corner of the window is locked, then click on it to unlock sharing
    At the top of the window there will be a field labeled "Computer Name:" make sure your computer has a name you'll recognize.
    Check "Remote Management"
    Click on the words "Remote Management
    If "Allow Access for:" is set to "All Users", Click the "Options.." button
    If "Allow Access for:" is set to "Only These Users:" then:
    if the user you wish to connect as is not on the "Only These Users:" list, click on the "+" button
    from the list of Users that pops up, select the user you wish to login with.
    click the "Select Button"
    you should be prompted with a list of actions you can allow to be remotely accessed by ARD.
    Check: Observe, Control, Show when being Observed, Generate Reports, Open and Quit Applications, Change Settings, Delete And Replace items, Start text chat or send Messages, Restart and Shutdown, Copy Items.
    Click the "OK" Button
    Cose System Preferences
    Your BMP should now be ready to be remotely connected to. (assuming the firewall on the BMP is off, and no other program like little snitch, or internet barrier is running)
    To connect to your BMP:
    On your ARD computer, open Apple Remote Desktop
    If you look on the left hand side of In Apple Remote Desktop there will be a column, the second item on the column listed Should be "Scanner" click on it
    Make sure scanner is set to "bonjour"
    from the list, on the right side of ARD you should see you BMP listed with what ever name you set in sharing.
    click on it, to select the computer
    click on the control screen icon from the tool bar.
    you will be prompted for the user name and password to use to connect to the computer.
    Good Luck!

  • Removing the Control Characters from a text file

    Hi,
    I am using the java.util.regex.* package to removing the control characters from a text file. I got below programming from the java.sun site.
    I am able to successfully compile the file and the when I try to run the file I got the error as
    ------------------------------------------------------------------------D:\Debi\datamigration>java Control
    Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repet
    ition
    {cntrl}
    at java.util.regex.Pattern.error(Pattern.java:1472)
    at java.util.regex.Pattern.closure(Pattern.java:2473)
    at java.util.regex.Pattern.sequence(Pattern.java:1597)
    at java.util.regex.Pattern.expr(Pattern.java:1489)
    at java.util.regex.Pattern.compile(Pattern.java:1257)
    at java.util.regex.Pattern.<init>(Pattern.java:1013)
    at java.util.regex.Pattern.compile(Pattern.java:760)
    at Control.main(Control.java:24)
    Please help me on this issue.
    Thanks&Regards
    Debi
    import java.util.regex.*;
    import java.io.*;
    public class Control {
    public static void main(String[] args)
    throws Exception {
    //Create a file object with the file name
    //in the argument:
    File fin = new File("fileName1");
    File fout = new File("fileName2");
    //Open and input and output stream
    FileInputStream fis =
    new FileInputStream(fin);
    FileOutputStream fos =
    new FileOutputStream(fout);
    BufferedReader in = new BufferedReader(
    new InputStreamReader(fis));
    BufferedWriter out = new BufferedWriter(
    new OutputStreamWriter(fos));
         // The pattern matches control characters
    Pattern p = Pattern.compile("{cntrl}");
    Matcher m = p.matcher("");
    String aLine = null;
    while((aLine = in.readLine()) != null) {
    m.reset(aLine);
    //Replaces control characters with an empty
    //string.
    String result = m.replaceAll("");
    out.write(result);
    out.newLine();
    in.close();
    out.close();

    Hi,
    I used the code below with the \p, but I didn't able to complie the file. It gave me an
    D:\Debi\datamigration>javac Control.java
    Control.java:24: illegal escape character
    Pattern p = Pattern.compile("\p{cntrl}");
    ^
    1 error
    Please help me on this issue.
    Thanks&Regards
    Debi
    // The pattern matches control characters
    Pattern p = Pattern.compile("\p{cntrl}");
    Matcher m = p.matcher("");
    String aLine = null;

  • Need help with Threading GUI progress bar

    Anyone able to help? I'm sure you've seen this a million times. I've google'd around and tried examples but still can't get a progress bar to work properly under the following situation:
    1. Created a panel with several components to select directory, display directory in tree etc.
    2. When a specific button (Search) is clicked, I want a secondary window to popup and report progress of searching down the directory.
    As you'll probably guess, the progress window isn't being updated until the end. I'm using Threads and using InvokeLater but nothing happens. Is there any good example that does the above? I can't seem to find one to figure this out.
    Thanks
    Speedy.
    Sample code:
    main.java:
    ========
    public class Main {
    public static void main(String[] args) {
    MainPanel mainPanel = new MainPanel();
    mainPanel.show();
    MainPanel.java:
    ============
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class MainPanel extends JFrame implements ActionListener {
    public MainPanel() {
    this.setSize(100,100);
    JButton startButton = new JButton("Start");
    this.getContentPane().add(startButton);
    startButton.addActionListener(this);
    public void actionPerformed(ActionEvent event) {
    ProgressPanel pp = new ProgressPanel();
    pp.show();
    SimpleTask st = new SimpleTask(pp);
    st.start();
    while (st.isAlive()) {
    System.err.println("waiting..");
    try {
    Thread.sleep(100);
    } catch (Exception e) {};
    System.err.println("finished!");
    SimpleTask.java:
    =============
    import javax.swing.SwingUtilities;
    public class SimpleTask extends Thread {
    ProgressPanel pp = null;
    public SimpleTask(ProgressPanel _pp) {
    pp = _pp;
    this.setDaemon(true);
    int i = 0;
    String position = "";
    public void run() {
    Runnable updateGUI = new Runnable() {
    public void run() {
    pp.setText(position);
    try {
    for (i=0; i<50; i++) {
    position = "Now on = " + new Integer(i).toString();
    System.err.println(position);
    SwingUtilities.invokeLater(updateGUI);
    sleep(100);
    } catch (Exception e) {}
    ProgressPanel.java:
    ===============
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class ProgressPanel extends JFrame {
    private JLabel label = new JLabel();
    public ProgressPanel() {
    this.setSize(200,200);
    this.setLocation(100,100);
    this.getContentPane().add(label);
    setText("Start");
    public void setText(String text) {
    label.setText(text);
    }

    Ok, I'll look down that road. I should have said the Thread is being used because the current while loop will be changed to perform real work. Just an example at the moment to show what I'm trying to do. Does this make a difference? The real task will be to drill down directories, counting file types/dirs etc...

  • AppleScript Needed...How to tell Pages to delete all texts with a specific color?

    How to tell Pages to remove all texts with the font size: 13 and color " disabledControlTextColor" from the developer palette?

    Sorry John,
    Now My question has changed,
    Now I want to fill the whole cell with a color , not only the text background
    Now I have the Solution. As from the previos post itself I got the Answer. I excuse all of u to put the related question in a new thread.
    Please leave it. I won't repeat it.
    <af:column sortProperty="Salary" headerText="#{bindings.EmployeesVO1.hints.Salary.label}"
    inlineStyle="#{row.Salary>'20000'?'background-color:Red;':'background-color:Orange;'}"
    id="c6">
    <af:outputText value="#{row.Salary}" id="ot4">
    <af:convertNumber groupingUsed="false"
    pattern="#{bindings.EmployeesVO1.hints.Salary.format}"/>
    </af:outputText>
    fixes my issue.
    Ranjith C
    Edited by: Ranjith C on Jun 30, 2011 4:46 AM

  • When texting with more than one person at a time the incoming text scrolls to top of the conversation. anyone out there with the same issue?

    while texting with more than one person at a time the incoming texts scrolls to top of conversation. anyone having this issue?

    I've heard claims it can be done, claims some have done it, and claims that it didn't work for them. This thread is interesting, some indications it should be possible, complaints that it didn't, and also an interesting work-around:
    "How do I text message multiple people at once?"
    http://discussions.apple.com/click.jspa?searchID=-1&messageID=4822260
    You can ask Apple for iPhone changes via this link:
    http://www.apple.com/feedback/iphone.html
    Though if you're requesting hardware changes for iPhone v2 you may want to wait a week (or a month?)...they're probably going to be inundated right now by requests for software changes to the current iPhone.
    (If this has answered your question, please mark your original post as answered)

  • Acrobat 9: Control over font in text box

    Versions: OS X 10.8.5 with Acrobat Pro 9, latest patch.
    I am experimentally preparing a four day training course by adding my instructor information to a PDF of the slide show.  There are only 850 slides, so it makes sense to experiment with this small document.
    All is going well.  I have created some custom stamps.  Acrobat has only crashed twice, losing not more than two hours work as a result.  I am optimistic I will be good to go in 10 more days.
    I have just copied some test into a text box and it copied as black and blue text with a larger font than the standard red font that I have been seeing until now.
    It occurs to me that this implies there may be some control over the text.  I realize that Acrobat is not meant to be a document preparation tool, so I hunted around somewhat for a way to change the text box text to not-red, gave up and I have been putting up with it until now.
    However, there are implications (but no clearly stated solutions) that there is a way to change the font, size and colour of text in text boxes.
    Do you know how?  I cannot work it out, nor can I find a solutoin.  I can see that the Commenting preference pane offers Small Medium and Large text.  There does not seem to be any other control other than the style (italic, bold, superscript, subscript) that is offered in the context menu.
    Hints?  Thoughts? 

    Pryanja.
    Thanks again.  If offers a dropdown for Colour, a box for style (plain, bold italic etc) and a button marked more, but they seem to do nothing at all.  They don't change what I type, and they don't affect selected text.  Looks to me tha they just take up some toolbar space.
    Is it possible that it does not work on Mac?

  • How To Use Control Hint Label In columnHeader?

    Using JDeveloper 9.0.3 I created a uiXML-BC4J app.
    I specified control hint Labels for each attribute in a view object whose source is a db table. The uix page browses the table using the view object. How do I get the column header to use the Control Hint Label? I'm currently hard coding column header text:
    <columnHeader>
    <bc4j:sortableHeader text="Product No" />
    </columnHeader>
    I would rather specify the control hint Label. How do I do that?
    Thanks for your time.
    Greg

    By "in the page", I meant just as you're doing it now.
    You could also externalize it to a Java ResourceBundle;
    see the "Internationalization" chapter of the UIX
    developer's guide.

  • Use Powershell to replace text with image in Word document

    I have a powershell script that uses a Word document as a template to create signatures that I am pushing out to my organization.
    The document is populated with text formatted the way I want the signature to look, that I then do a FindText and ReplaceText on.  This works fine for replacing text with text, but I can't figure out how to properly replace some of the holder text with
    an image and a link.  I found a few posts about adding images to word documents, but none that seem to work properly in this scenario.
    Any insight would be greatly appreciated, thanks!

    Dear BOFH,
    You are correct that method I outlined is not for inserting an image into a signature block (which would be in Outlook, not Word).  The links you post do certainly deal with outlook signatures, well done... Except that the question was about how to
    use a Powershell script to replace text in a Word document with an image.  Sure it was framed in the context of creating signatures, but the poster expressed that they already had a method of generating and replacing text, and just needed to know, as
    I did, how to do the thing they actually asked.
    Please BOFH... Please forgive my audacity in hoping to find a reference (any reference) to how to replace Word text with images via Powershell in a thread titled "Use Powershell to replace text with image in Word document".
    This is certainly a scripting question, and even something as simple as "You will need to call the .NET methods for the Word find/replace functionality.  Please ask in the Word forums for the correct method to use. 
    If you need help on calling .NET methods look HTTP ://here"support you offered combined with the contempt you offer in response to my actual substantive help to the actual question asked.
    BOFH, you are not better than us, just more arrogant.
    Can you please start your own question as this one has been closed.  Please see scripting guidelines.
    We cannot guarantee you satisfaction as this is a user supported forum.  The is no SLA for community support.  Perhaps if you posted a better worded question as a new topic someone might be able to help you resolve your issue.
    The topic you are posting on is closed and answered.
    ¯\_(ツ)_/¯

  • How to remove labels from text fields?

    Hey Everyone!
    I am having troubles with forms in Dreamweaver CC.
    I insert a text field in a form but the text field automatically comes with a label.
    How do i stop this?

    And I get that!
    But say I insert a text field.
    It is preceded by a label saying "Text Field 1:"
    But I already have written what the text field is supposed to do!
    And when I go in front of the label and press backspace, it doesn't wanna get deleted; not until I have to select the text and delete it!
    So you see a large part of my time is getting wasted in formatting the page and i can't give my full attention to the php code I want to write as I get frustrated because of this!
    So if you could help me get rid of the labels for good ; it'll be amazing!
    Thanks
    Regards
    Anuj

  • Design issue with threads ...

    Hello,
    I need your thoughts in how to proper use java threads in solving this issue:
    * I have an application that query a database for a list of users, and for each row retrieved from the database as a result the application should process that user and send him an email.
    Now the procdural approach for looping each user and send him an email at a time is not convinient as the number of users is big (20,000 users or more) so I thought of why not to use threads to send say every 300 user at a time (i.e, creating 300 threads), but the problem is that I cannot really figure how to manage those threads, to make sure that there are 300 threads are running all the time, and what if a thread was taking more time that the others ... etc.
    So, is this approach is the right one, and can you guide more more for how to control the threads this way, if not what do you suggest?
    Your guidance is highly appreciated,
    tamer

    I'm not sure that threads will help your cause. But they could. Let me explain:
    Threads have several purposes. Two instantly spring to mind:
    1. to make things faster.
    2. to (make it seem like you) do two (or more things) at once.
    First #2. This is often a usability issue. For example, a web server has to server multiple clients at the "same time". This is often done with threads - it gives the illusion that many concurrent users are supported. In reality the CPU/JVM is swapping beween the different requests. More CPUs allow for "realer" concurrency. Speed is only a by-product here.
    Now #1: Make things faster. Threading works well for speed when the tasks being done differ.
    For example, consider human multithreading: ask me to whistle for 5 seconds, and 5 seconds later I'll be done. Then ask me to scratch my head with both hands for 5 seconds, and 5 seconds later I'll be done. Total: 10 seconds. Ask me to do both at the same time. Result: 5 seconds later I'll have scratched my head and whistled for 5 seconds. 50% time saving.
    However, ask me to touch type for 5 seconds, and scratch my head for 5 seconds, it'll take 10 seconds or more. If you ask me to do one, then the other, I can spend 5 seconds at one then the other - total 10 seconds. Ask me to do both concurrently, and I'll take more than 10 seconds, as I'll be moving my hands back and forth from the keyboard to my head, and vice-versa.
    I have a feeling that running multiple threads in your case would be like asking you to scratch your head and scratch your head all at the same time. But this may not strictly hold true for several reasons:
    1. your DB should scale, i.e. handle two simultaneous requests faster than two concurrent requests. However, this will probably not be true of 300 simultaneous requests being faster than 300 concurrent (or 50 * 6-concurrent requests).
    2. if you are in a multi-CPU environment then some concurrentcy improvements would be expected (more hands for head scratching).
    3. your application does two things: reads a DB and sends a mail. While sending one mail, you should be albe to concurrently read the next record. i.e. concurrency is supported here, as you don't have resource contention here.
    So, you will probably get some benefit from threads. Adding too many will only slow you down, as there'll be too much time spend task switching, as you'll suffer resource contenion on the DB/mail server.
    I suggest that you run your program with several configurations, i.e. number of threads, and see what one gives the best results. For fast results, I'd suggests trying the following number of threads:
    1, 2, 4, 8, 16, 32, 64, 128, 256, ...
    when things start to slow down, you know where to search for your optimum thread number. You could also do with profiling your application if speed is a very pressing issue.
    Finally, one clarification: this is not OO. You could do multi-threading in a procedural environment.
    Good luck.
    if you are running on a multi-CPU environment, then the DB

  • I have a 4 month long text message thread conversation. What's the quickest way to get to the very beginning of the conversation?

    I have a 4 month long text message thread conversation. What's the quickest way to get to the very beginning of the conversation?

    The startup.exe file is locate in the \NI-RT\STARTUP directory. 'cd NI-RT' then 'cd STARTUP' should get you to the right place after making the connection with ftp. I don't recognize PH_EXEC.EXE. Logging in as anonymous is fine. I don't recall seeing documentation on the file structure and locations on the module but I'm sure there is some. I just wandered around w/ftp.
    The program to update the node should be below. Enter the IP address, the green light will confirm the node is found.
    The version function scans the existing startup.exe for a string beginning and ending with " RU Version " and prints everything in between as the version.
    The autostart function will copy the existing ni-rt.ini file to your computer, mod
    ify the autostart as requested, then put the file back. Leaves the copy on the PC, which can be handy.
    Send file will request a file of the format startup*.dat which will be renamed startup.exe and ftp'd to the module. Lets you keep version numbers in the filename on the PC side. Your directory structure probably won't match mine so you'll have to browse for your file.
    Reboot module reboots the module.
    Hope this is useful, let me know if anything doesn't make sense. Thanks.
    Matt
    Attachments:
    RNconfig.exe ‏855 KB

  • Text with slide show

    I saw a slide show that I think was made with iDVD that had text identifying the photo. Was this something done with software like Photoshop? I can find nothing in iDVD that would allow me to insert text with a photo.
    Also during my first attempt of putting in photos from iphoto I got a notice that I could only put in 30 photos. Consequently I put in sub menus creating three sections for 90 photos. It know seems that I didn't need to do that as it appears that you can use 99 photos. I can't remember the sequence of events that prompted the notice of 30 photo maximum but it did happen.
    Doug

    Hi Douglas
    To Your first question. Yes I would bet on that it was done with PhotoShop™
    or any other photo editing program.
    Your second: Dont know. I use iMovie to make my slideshows and here
    there are no limit and a much higher controll over the presentation. You
    could even put text on Your photos here but in a rather crude way.
    BUT - there are lots of people saying that there is a resolution loss this
    way. I think that it has to do with how You go from iMovie to iDVD (not
    via the Share/Export to iDVD from within imovie - but - just drop the
    project icon into an open iDVD theme window).
    Yours Bengt W

  • Need some help with threads...

    Hello all,
    I am working on a project at work, and I am not the best programmer in the world. I have been trying to get my head around this for a couple of days and just cannot get it to work.
    I am writing an instrumentation control program that will have three threads. One is the GUI, one will receive control information and set up the hardware, and one will check the hardware status and report it to the GUI periodically. I plan on using the invokeLater() method to communicate the status to the GUI and change the status display in the GUI. Communication from the GUI to the controller thread and from the status thread to the controller thread I had planned on being piped input/output stream as appropriate. I have a control class and a status class that need to be communicated over these piped streams. In some trial code I have been unable to wrap the piped input/output streams with object input/output streams. I really need some help with this. Here is the main thread code:
    package playingwiththreads1;
    import java.io.*;*
    *public class PlayingWithThreads1 {*
    public static void main(String[] args) {*
    * PipedOutputStream outputPipe = new PipedOutputStream();*
    * ObjectOutputStream oos = null;*
    * ReceiverThread rt = new ReceiverThread(outputPipe);*
    // Start the thread -- First try*
    * Thread t = new Thread(rt);*
    t.start();*
    // Wrap the output pipe with an ObjectOutputStream*
    try*
    oos = new ObjectOutputStream(outputPipe);*
    catch (IOException e)*
    System.out.println(e);*
    // Start the thread -- Second try*
    //Thread t = new Thread(rt);*
    //t.start();*
    /** Send an object over the pipe. In reality this object will be a
    class that contains control or status information */
    try
    if (!oos.equals(null))
    oos.writeObject(new String ("Test"));
    catch (IOException e)
    try
    Thread.sleep(5000);
    catch (InterruptedException e)
    I read somewhere that it matters where you start the thread relative to where you wrap piped streams with the object streams. So, I tried the two places I felt were obvious to start the thread. These are noted in the comments. Here is the code for the thread.
    package playingwiththreads1;
    import java.io.*;
    public class ReceiverThread implements Runnable {
    private PipedInputStream inputPipe = new PipedInputStream();
    private ObjectInputStream inputObject;
    ReceiverThread (PipedOutputStream outputPipe)
    System.out.println("Thread initialization - start");
    try
    inputPipe.connect(outputPipe);
    inputObject = new ObjectInputStream(inputPipe);
    catch (IOException e)
    System.out.println(e);
    System.out.println("Thread initialization - complete");
    public void run()
    System.out.println("Thread started");
    try
    if (inputObject.available() > 0)
    System.out.println(inputObject.read());
    catch (IOException e)
    System.out.println(e);
    Through testing I have determined that no matter where I start the thread, the thread never gets past the "inputObject = new ObjectInputStream(inputPipe);" assignment.
    Could someone please help me with this? There are other ways for me to write this program, but this is the one that I would like to make work.
    Many thanks in advance,
    Rob Hix
    Edited by: RobertHix on Oct 6, 2009 3:54 AM

    Thanks for the help, but that did not work. I tried flushing the ObjectOutputStream and it is still hanging when initializing the thread.
    Here is a better look at the code since I was helped to figure out how to insert it:
    The main method:
    package playingwiththreads1;
    import java.io.*;
    public class PlayingWithThreads1 {
        public static void main(String[] args) {
            PipedOutputStream outputPipe = new PipedOutputStream();
            ObjectOutputStream oos = null;
            ReceiverThread rt = new ReceiverThread(outputPipe);
            // Start the thread -- First try
            //Thread t = new Thread(rt);
            //t.start();
            // Wrap the output pipe with an ObjectOutputStream
            try
                oos = new ObjectOutputStream(outputPipe);
                oos.flush();
            catch (IOException e)
                System.out.println(e);
            // Start the thread -- Second try
            Thread t = new Thread(rt);
            t.start();
            /* Send an object over the pipe.  In reality this object will be a
             * class that contains control or status information */
            try
                if (!oos.equals(null))
                    oos.writeObject(new String ("Test"));
                    oos.flush();
            catch (IOException e)
                System.out.pringln(e);
            try
                Thread.sleep(5000);
            catch (InterruptedException e)
    }The thread code:
    package playingwiththreads1;
    import java.io.*;
    public class ReceiverThread implements Runnable {
        private PipedInputStream inputPipe = new PipedInputStream();
        private ObjectInputStream inputObject;
        ReceiverThread (PipedOutputStream outputPipe)
            System.out.println("Thread initialization - start");
            try
                inputPipe.connect(outputPipe);
                inputObject = new ObjectInputStream(inputPipe);
            catch (IOException e)
                System.out.println(e);
            System.out.println("Thread initialization - complete");
        public void run()
            System.out.println("Thread started");
            try
                if (inputObject.available() > 0)
                    System.out.println(inputObject.read());
            catch (IOException e)
                System.out.println(e);
    }Does anyone else have and ideas?

Maybe you are looking for