所以我有两个类,一个类扩展了主类,我正在使用swing,当我想在主类中设置setTitle或其他东西时,我得到了:
Exception in thread "main" java.lang.UnsupportedOperationException: Not supported yet.
at javaapplication5.PrviProzor.setTitle(PrviProzor.java:166)
at javaapplication5.Timer1.main(Timer1.java:15)
这是Main类中的代码:
int opcija = JOptionPane.showOptionDialog(null, "Choose option", "Option dialog", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {"Settings", "Close"}, null);
if(opcija==JOptionPane.YES_OPTION){
PrviProzor prviProzor = new PrviProzor();
prviProzor.setTitle("Timer");
prviProzor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
prviProzor.setLocationRelativeTo(null);
prviProzor.setVisible(true);
}
if(opcija==JOptionPane.NO_OPTION){
exit();
}
并且程序希望我将setTitle,setDefaultCloseOperation ..和其余方法放在第二类中,这些是默认方法:
void setTitle(String timer) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
void setDefaultCloseOperation(int EXIT_ON_CLOSE) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
void setLocationRelativeTo(Object object) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
void setVisible(boolean b) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
And the program still doesn't work, I still get the java.lang.UnsupportedOperationException. What should I do?
答案 0 :(得分:-2)
如何实现实际方法?
编辑: 好的,以防万一有人仍然不了解它。
void setTitle(String timer) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
假设您自动生成了类,并且这是PrviProzor类中的实现,那么您需要将其实现为 real 。否则我只能说,您的代码按预期运行。