Good day.
Is there any way to set parameters for a specific group of elements? (for example, for JButton buttons)
How to create this group?
If not, can one element, in any way, inherit the parameters from another element?
Good day.
Is there any way to set parameters for a specific group of elements? (for example, for JButton buttons)
How to create this group?
If not, can one element, in any way, inherit the parameters from another element?
You can for example:
public class MyJButton extends JButton { public MyJButton(final int xLoc, final int yLoc) { this.setSize (new Dimension (100, 20)); this.setLocation (xLoc, yLoc); } } You can pass some parameters to the constructor, just set some of them inside. You can still like this:
public class JButtonFactory { public static JButton giveMeButton(final int xLoc, final int yLoc) { JButton jButton = new JButton (); jButton.setSize (new Dimension (100, 20)); jButton.setLocation (xLoc, yLoc); return jButton; } } Naturally, you will need to add button lebels, cover the container, location coordinates, etc.
Source: https://ru.stackoverflow.com/questions/622520/
All Articles