java 抽象接口中的用户对象
User object in java abstract interface
我看到传递变量值的抽象内容是接口。请告诉我如何运行那些功能
public interface Style {
void display();
}
public abstract class ActionFrame {
//Pass the parameter to the function is the interface
void addStyle(Style style) {
}
}
public class Test {
public static void main(String[] args) {
//Call class abstract
CActionFrame cActionFrame = new CActionFrame();
//Call function addStyle with parameter is the interface : Style
cActionFrame.addStyle(new Style() {
//Override function display() in Style
@Override
public void display() {
//I want to display text : "This is Test" but when run result is not output display
System.out.println("This is Test");
}
});
//How to call display ()
cActionFrame.?
}
}
我的问题你遇到过很多这样的说法。
btnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
如果我没理解错的话,你想调用传递的Style
对象的display
方法,对吧?然后是这样的:
public interface Style {
public void display();
}
public abstract class ActionFrame {
private Style mStyle;
public void addStyle(Style style) {
mStyle = style;
}
public Style getStyle(){
return mStyle;
}
}
public class Test {
public static void main(String[] args) {
CActionFrame cActionFrame = new CActionFrame();
cActionFrame.addStyle(new Style() {
@Override
public void display() {
System.out.println("aaaaaaaaaaaaaaa");
}
});
cActionFrame.getStyle().display();
}
}
我看到传递变量值的抽象内容是接口。请告诉我如何运行那些功能
public interface Style {
void display();
}
public abstract class ActionFrame {
//Pass the parameter to the function is the interface
void addStyle(Style style) {
}
}
public class Test {
public static void main(String[] args) {
//Call class abstract
CActionFrame cActionFrame = new CActionFrame();
//Call function addStyle with parameter is the interface : Style
cActionFrame.addStyle(new Style() {
//Override function display() in Style
@Override
public void display() {
//I want to display text : "This is Test" but when run result is not output display
System.out.println("This is Test");
}
});
//How to call display ()
cActionFrame.?
}
}
我的问题你遇到过很多这样的说法。
btnButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
});
如果我没理解错的话,你想调用传递的Style
对象的display
方法,对吧?然后是这样的:
public interface Style {
public void display();
}
public abstract class ActionFrame {
private Style mStyle;
public void addStyle(Style style) {
mStyle = style;
}
public Style getStyle(){
return mStyle;
}
}
public class Test {
public static void main(String[] args) {
CActionFrame cActionFrame = new CActionFrame();
cActionFrame.addStyle(new Style() {
@Override
public void display() {
System.out.println("aaaaaaaaaaaaaaa");
}
});
cActionFrame.getStyle().display();
}
}