我不知道正确的术语,这有点限制了我的搜索,我想创建一个带有设置JFrame的类,另一个带有按钮属性(JButton)。我想创建尽可能多的类来扩展这个按钮类,创建添加到屏幕的新按钮。这个扩展按钮的类只需要几个方法来设置setBounds,Color,text等。我不希望这些扩展类被主类或按钮类“知道”,这意味着我不必更改按钮类或主类中的任何内容来添加按钮,只需将一个将按钮扩展的类拖到包中对不起,如果这没有多大意义,我尽可能地解释它。我的主要课程看起来像这样:
import javax.swing.JFrame;
public class screen extends JFrame{
public screen(){
setSize(600,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setBackground(Color.WHITE);
setVisible(true);
}
public static void main(String[] args){
new screen();
}
}
是的,不多,因为我不知道在这个按钮课上从哪里开始。我只是制作一些带参数的方法。如果这个问题似乎有点长,无法回答,那么他们的名字是我想要完成的吗?感谢。
我添加了这个部分,如果可能的话,我正在寻找的想法:
int x, y, locX, locY;
Color color;
public button(Color color, int x, int y, int locX, int locY){
this.x = x;
this.y= y;
this.locX = locX;
this.locY = locY;
this.color=color;
setBounds(x, y, locX, locY);
setForeground(color);
}
}