Prev: Collections - Set to prevent duplicating items
Next: Simple Hack To Get $2000 To Your PayPal Account
From: Sal on 12 Jul 2010 17:41 In the following test applet, I would like to have the "Begin counting " display immediately, and the "End counting" to display when finished, instead the applet waits until the end of the counting loop and then displays the text all at once. How can I get it to work properly? public class Test extends JApplet { JScrollPane scrollPane; JTextArea textArea; Color darkGreen = new Color( 0, 160, 0 ); //medium dark green int nbrOfTimes = 0x7fffffff; private void setNativeLookAndFeel() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { textArea.append("Error setting native LAF: " + e + "\n"); } } public void init() { setNativeLookAndFeel(); Container cp = getContentPane(); cp.setBackground( darkGreen ); cp.setLayout( new FlowLayout() ); textArea = new JTextArea(30, 40); scrollPane = new JScrollPane(); cp.add ( new JScrollPane( textArea ) ); textArea.setEditable( false ); textArea.append( "Begin counting " + nbrOfTimes +" \n" ); // <------ look here int ctr = 0; while( ++ctr < nbrOfTimes ); textArea.append( "End counting " + ctr +" \n" ); // <------- look here } }
From: Joshua Cranmer on 12 Jul 2010 18:25 On 07/12/2010 05:41 PM, Sal wrote: > In the following test applet, I would like to have the "Begin counting > " display immediately, and the "End counting" to display when > finished, instead the applet waits until the end of the counting loop > and then displays the text all at once. How can I get it to work > properly? Answer the following questions: 1. What are the methods called over the lifecycle of an applet, and in what order? 2. On what thread or threads are these methods called? 3. When is the content of an applet actually displayed? If you can correctly answer all three questions, you should realize why the text displays all at once. Moving some of the code elsewhere will ameliorate this problem; which code and where is left as an exercise to the reader. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
From: Sal on 12 Jul 2010 18:41 On Jul 12, 3:25 pm, Joshua Cranmer <Pidgeo...(a)verizon.invalid> wrote: > On 07/12/2010 05:41 PM, Sal wrote: > > > In the following test applet, I would like to have the "Begin counting > > " display immediately, and the "End counting" to display when > > finished, instead the applet waits until the end of the counting loop > > and then displays the text all at once. How can I get it to work > > properly? > > Answer the following questions: > 1. What are the methods called over the lifecycle of an applet, and in > what order? > 2. On what thread or threads are these methods called? > 3. When is the content of an applet actually displayed? > > If you can correctly answer all three questions, you should realize why > the text displays all at once. Moving some of the code elsewhere will > ameliorate this problem; which code and where is left as an exercise to > the reader. > > -- > Beware of bugs in the above code; I have only proved it correct, not > tried it. -- Donald E. Knuth Thanks for your reply. You are very lucky as it's obvious you were never a beginner.
From: Jeff Higgins on 12 Jul 2010 19:58 On 7/12/2010 6:41 PM, Sal wrote: > On Jul 12, 3:25 pm, Joshua Cranmer<Pidgeo...(a)verizon.invalid> wrote: >> On 07/12/2010 05:41 PM, Sal wrote: >> >>> In the following test applet, I would like to have the "Begin counting >>> " display immediately, and the "End counting" to display when >>> finished, instead the applet waits until the end of the counting loop >>> and then displays the text all at once. How can I get it to work >>> properly? >> >> Answer the following questions: >> 1. What are the methods called over the lifecycle of an applet, and in >> what order? >> 2. On what thread or threads are these methods called? >> 3. When is the content of an applet actually displayed? >> >> If you can correctly answer all three questions, you should realize why >> the text displays all at once. Moving some of the code elsewhere will >> ameliorate this problem; which code and where is left as an exercise to >> the reader. >> > > Thanks for your reply. You are very lucky as it's obvious you were > never a beginner. A good place for beginners is the Java Tutorials. <http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/index.html> Under the section "Trails Coverings the Basics", "Deployment" includes a trail on Java Applets. Under the section "Creating a GUI with Swing" you can learn about Text Components and Events. As always: The Java SE 6 Documentation <http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/> and The Java SE 6 API Specification <http://download-llnw.oracle.com/docs/cd/E17409_01/javase/6/docs/api/>
From: Jeff Higgins on 12 Jul 2010 20:16 On 7/12/2010 6:41 PM, Sal wrote: > On Jul 12, 3:25 pm, Joshua Cranmer<Pidgeo...(a)verizon.invalid> wrote: >> On 07/12/2010 05:41 PM, Sal wrote: >> >>> In the following test applet, I would like to have the "Begin counting >>> " display immediately, and the "End counting" to display when >>> finished, instead the applet waits until the end of the counting loop >>> and then displays the text all at once. How can I get it to work >>> properly? >> >> Answer the following questions: >> 1. What are the methods called over the lifecycle of an applet, and in >> what order? >> 2. On what thread or threads are these methods called? >> 3. When is the content of an applet actually displayed? >> >> If you can correctly answer all three questions, you should realize why >> the text displays all at once. Moving some of the code elsewhere will >> ameliorate this problem; which code and where is left as an exercise to >> the reader. >> > Thanks for your reply. You are very lucky as it's obvious you were > never a beginner. Many of the more experienced readers of this group began at the beginning and worked through the basics by reading the documentation and writing code and experimenting. A beginner following this path will quickly become confident in their knowledge of the basics. See my other post for pointers toward the beginning.
|
Next
|
Last
Pages: 1 2 3 4 Prev: Collections - Set to prevent duplicating items Next: Simple Hack To Get $2000 To Your PayPal Account |