Click here to Skip to main content
15,887,822 members
Home / Discussions / Java
   

Java

 
GeneralRe: Java Parallel Port Interfacing Pin
Fahimul719-Mar-10 0:27
Fahimul719-Mar-10 0:27 
GeneralRe: Java Parallel Port Interfacing Pin
Richard MacCutchan19-Mar-10 1:20
mveRichard MacCutchan19-Mar-10 1:20 
GeneralRe: Java Parallel Port Interfacing Pin
Fahimul719-Mar-10 3:24
Fahimul719-Mar-10 3:24 
QuestionFirst Fit Help Pin
Blackberry8917-Mar-10 10:15
Blackberry8917-Mar-10 10:15 
AnswerRe: First Fit Help Pin
TorstenH.18-Mar-10 2:14
TorstenH.18-Mar-10 2:14 
QuestionJava Conversions Pin
James WG Murphy17-Mar-10 7:34
James WG Murphy17-Mar-10 7:34 
AnswerRe: Java Conversions Pin
Richard MacCutchan17-Mar-10 7:55
mveRichard MacCutchan17-Mar-10 7:55 
AnswerRe: Java Conversions [modified] Pin
TorstenH.18-Mar-10 2:02
TorstenH.18-Mar-10 2:02 
Lets start with simple things:

1. do not use main for greating a GUI - let another object do it for you:
public static void main (String[] args) {
 View oView = new View();
}


2. do not set up several static classes with nearly same content. Again, use objects - in this case you need 1 class for the actions which you can use serveral times. Put your classes in seperate files!

public class View extends JFrame{

// members
JPanel oPanel = new JPanel();
JButton oButton = new JButton("click");


// constructor
public View(){
oButton.addActionListener(oActionListener);  
oPanel.add(oButton);


// anonymous class
ActionListener oActionListener = new ActionListener() {
 public void actionPerformed(ActionEvent oEvent) {
  if (oEvent.equals("something")){
   //do any();
  }
  else if(...){
  }
 }
};

this.add(oPanel);

}


You could even use a method for creating all the buttons - any line just needs to be writen once:
JButton oButton = createButton("click");

private JButton createButton(final String strCommand){
 JButton oButton = new JButton(strCommand);
 oButton.addActionListener(oActionListener);
 return oButton;
}


The ActionListener can again use some object which does the conversion... for information on how to convert things you should search the net.

EDIT: please do not name classes by simular keywords - this will ruin your day someday!

greets
Torsten
I never finish anyth...
modified on Thursday, March 18, 2010 8:15 AM

QuestionJNLP Error Pin
002comp16-Mar-10 22:37
002comp16-Mar-10 22:37 
AnswerRe: JNLP Error(Solved) Pin
002comp17-Mar-10 0:05
002comp17-Mar-10 0:05 
AnswerRe: JButton Help Pin
Richard MacCutchan16-Mar-10 22:47
mveRichard MacCutchan16-Mar-10 22:47 
GeneralRe: JButton Help Pin
James WG Murphy17-Mar-10 2:58
James WG Murphy17-Mar-10 2:58 
GeneralRe: JButton Help Pin
Richard MacCutchan17-Mar-10 4:04
mveRichard MacCutchan17-Mar-10 4:04 
GeneralRe: JButton Help Pin
David Skelly17-Mar-10 6:19
David Skelly17-Mar-10 6:19 
AnswerRe: JButton Help Pin
David Skelly16-Mar-10 23:29
David Skelly16-Mar-10 23:29 
Questiondate_time problum in java?? Pin
AmbiguousName16-Mar-10 2:34
AmbiguousName16-Mar-10 2:34 
AnswerRe: date_time problum in java?? Pin
O.Phil16-Mar-10 3:02
O.Phil16-Mar-10 3:02 
GeneralRe: date_time problum in java?? Pin
AmbiguousName16-Mar-10 3:15
AmbiguousName16-Mar-10 3:15 
Questionuser authentication Pin
Kunalpuranik15-Mar-10 19:04
Kunalpuranik15-Mar-10 19:04 
AnswerRe: user authentication Pin
Richard MacCutchan15-Mar-10 22:29
mveRichard MacCutchan15-Mar-10 22:29 
GeneralRe: user authentication Pin
Kunalpuranik16-Mar-10 0:32
Kunalpuranik16-Mar-10 0:32 
GeneralRe: user authentication Pin
Richard MacCutchan16-Mar-10 3:30
mveRichard MacCutchan16-Mar-10 3:30 
GeneralRe: user authentication Pin
David Skelly16-Mar-10 3:39
David Skelly16-Mar-10 3:39 
GeneralRe: user authentication Pin
Richard MacCutchan16-Mar-10 4:15
mveRichard MacCutchan16-Mar-10 4:15 
QuestionJava3D Pin
java3dArtist15-Mar-10 0:03
java3dArtist15-Mar-10 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.