From: Lew on 15 Feb 2010 15:16 Amr wrote: > the program somewhat working now after making some changes from the > given suggestion. > > import java.awt.event.ActionEvent; > import java.awt.event.ActionListener; > import javax.swing.*; > import java.awt.*; > import net.miginfocom.swing.MigLayout; > > public class AL2 extends JFrame implements ActionListener{ > > JTextField countText=new JTextField(20); Why do you use package-private (a.k.a. "default") access instead of private? > JButton button=new JButton("Click to increment"); > private int numClicks=0; Initialization of a member variable to zero is redundant, causing zero to be assigned to it twice. (The same holds true of initialization of a reference member to 'null'.) The performance impact is negligible, though, and some will argue that the explicit initialization is useful for code maintainers. > public AL2(){ > > super(); The explicit invocation of the no-argument 'super()' constructor is completely unnecessary. > themes(); > > > // Dimension > d=java.awt.Toolkit.getDefaultToolkit().getScreenSize(); > // setSize(d); > JPanel pane=new JPanel(new MigLayout("Wrap 1")); > button.addActionListener(this); > pane.add(countText); > pane.add(button); > add(pane); > > setVisible(true); > pack(); The call to 'pack()' should come before the call to 'setVisible()'. > } > > public void themes(){ > > try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); > SwingUtilities.updateComponentTreeUI(this);}catch (Exception e) > { > System.out.println("errror in applying the theme"); > } > } Please use conventional indentation to keep your code readable. > public void actionPerformed(ActionEvent e){ > numClicks++; > countText.setText("Button CLicked"+numClicks+"Times"); > } > > public static void main(String arg[]){ > AL2 a=new AL2(); > } > } You continue to perform GUI operations not on the EDT. This is dangerous and will lead to weird bugs. Several folks have mentioned this to you. > PS: is there any way in this group that each and every mail lands in > my email box, so that i [sic] can reply from there itself without coming to > the webpage? No. This is a newsgroup, not a web page. The posts are not emails, but newsgroup posts. It's like the difference between a paper letter that you send via the post office, and an index card announcement that you post on a community bulletin board. Don't use a web interface, use a newsreader instead. markspace mentioned Mozilla Thunderbird, a decent one although not necessarily the best. You will need access to a news server if you use a newsreader. -- Lew
From: Arshad on 17 Feb 2010 00:30 thank you guys for the help and suggestions. i greatly appreciate this. > Please use conventional indentation to keep your code readable. is that mean, i should delete all the tabs indents infront of the lines? (i left it as it was in netbeans ide, bcz i heard from some one that using tabs is a good programming practice :confused:) > You continue to perform GUI operations not on the EDT. This is dangerous and > will lead to weird bugs. Several folks have mentioned this to you. actually i didnt understand what an EDT is. i will do some searching/reading about this and will try to stick to that. thank you.
From: Lew on 17 Feb 2010 01:57 Arshad wrote: >> Please use conventional indentation to keep your code readable. Please attribute when you're quoting. > is that mean, i should delete all the tabs indents infront of the > lines? For Usenet, yes - TAB characters get rendered very wide and newsreaders tend to break and wrap lines with relatively narrow margins. This makes source listings on Usenet very hard to read and decipher when TAB characters indent lines. Particularly when you're asking for help, you don't want to make your code examples hard to read. > (i left it as it was in netbeans ide, bcz [!?] i heard from some one that > using tabs is a good programming practice :confused:) Be careful whom you listen to. There's a lot of bad advice out there. Nearly every programming project I have been on standardized on spaces, not TAB characters for indentation. You can control indentation precisely with spaces. Not so with TABs - you're at the mercy of different settings for TAB rendition in different editors and different workstations. Plus, TABs tend to render far too wide by default. As for leaving it the way it was in NetBeans, that is a circular argument. Since you chose how it was in NetBeans, you are effectively saying you chose to leave it as you chose to leave it. >> You continue to perform GUI operations not on the EDT. This is dangerous and >> will lead to weird bugs. Several folks have mentioned this to you. > > actually i didnt understand what an EDT is. > i will do some searching/reading about this and will try to stick to > that. EDT is the Event Dispatch Thread. Read the Swing tutorial on java.sun.com. Java is a multi-threaded language - you have the power and the responsibility to coordinate threads. Graphics instructions need to occur on a single singular thread called the "EDT" in order for things to coordinate properly. This is introduced in the Swing tutorial on java.sun.com. If you don't use the EDT properly you'll get weird bugs, as with all threading mistakes. -- Lew The word "I" in English is capitalized. Proper nouns are capitalized. Trademark names have particular and often non-standard capitalization. "bcz" is not an English word. Typing is not heavy lifting.
From: RedGrittyBrick on 17 Feb 2010 04:59 On 17/02/2010 05:30, Arshad wrote: > thank you guys for the help and suggestions. > i greatly appreciate this. > >> Please use conventional indentation to keep your code readable. > > is that mean, i should delete all the tabs indents infront of the > lines? No, have your IDE convert those tabs to multiple spaces. I configure my IDE to use spaces (not tab characters) for indentation and I set the indentation to 4 spaces. Sometimes I reduce indentation to two spaces for posting to usenet. Your IDE can quickly reformat your code for you. > (i left it as it was in netbeans ide, bcz i heard from some one that > using tabs is a good programming practice :confused:) It's an ancient debate carried over from previous millenia. http://www.jwz.org/doc/tabs-vs-spaces.html I find tab characters hinder far more than they help. This is especially true on usenet.
From: Arne Vajhøj on 17 Feb 2010 17:56 On 17-02-2010 01:57, Lew wrote: >> is that mean, i should delete all the tabs indents infront of the >> lines? > > For Usenet, yes - TAB characters get rendered very wide and newsreaders > tend to break and wrap lines with relatively narrow margins. This makes > source listings on Usenet very hard to read and decipher when TAB > characters indent lines. Particularly when you're asking for help, you > don't want to make your code examples hard to read. I think you need to emphasize that tabs should not be deleted but replaced with spaces (usually 4 per tab). >> (i left it as it was in netbeans ide, bcz [!?] i heard from some one that >> using tabs is a good programming practice :confused:) > > Be careful whom you listen to. There's a lot of bad advice out there. > > Nearly every programming project I have been on standardized on spaces, > not TAB characters for indentation. You can control indentation > precisely with spaces. Not so with TABs - you're at the mercy of > different settings for TAB rendition in different editors and different > workstations. Plus, TABs tend to render far too wide by default. I am all for spaces. The only argument for tabs that I know of is that it allows different users to use different indentation. Which is a nice theory. But the reality is that people always use some spaces and when changing the tab definition the result looks horrible. Arne
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: ANN: GR8 in the US 2010 Conference Registration Now Open! Next: Simple BorderLayout problem |