Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Arland Smith   on Oct 14 In Java Category.

  
Question Answered By: Adalric Fischer   on Oct 14

The button  is not being initialized correctly because you set the
attributes of a local JButton which gets destroyed as soon as the
c'tor exits. Instead, use the super() function to call the appropriate
superclass c'tor and then set the remaining attributes  as necessary
for the object being constructed.

class mybutton extends JButton {
mybutton(String name) {
super(name);
setBackground(Color.red);
setForeground(Color.white);
setBorder(
new javax.swing.border.CompoundBorder(
new javax.swing.border.SoftBevelBorder(
javax.swing.border.BevelBorder.RAISED),
new javax.swing.border.BevelBorder(
javax.swing.border.BevelBorder.RAISED)));
setBackground(Color.blue);
setForeground(Color.white);
}
}

This uses the JButton(String) c'tor to set the button name, then sets
the attributes of the mybutton being created. Since mybutton
subclasses JButton, all JButton functions will work on mybutton.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on what wrong wit it Or get search suggestion and latest updates.


Tagged: