getContentPane问题

jin_zh 2014-07-18 12:56:59


提示错误:The method getContentPane() is undefined for the type
...全文
456 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jin_zh 2014-07-21
  • 打赏
  • 举报
回复
我在FrameTest中继承了一下JFrame就解决问题了
KK3K2005 2014-07-18
  • 打赏
  • 举报
回复
this. getContentPane 把 不然怎么编译怎么找到
KK3K2005 2014-07-18
  • 打赏
  • 举报
回复
好吧 你看的什么书啊 getContentPane 这个东西是谁的呢?呵呵 你看你代码 你那个对象有 getContentPane了 是jframe? class FrameTest { JFrame frameObj; public FrameTest() { frameObj=new JFrame("window"); frameObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frameObj.setVisible(true); frameObj.setSize(600,400); } public ??? getContentPane(){ //这里的??? 你自己写一下返回类型 return this.frameObj.getContentPane(); } } 另外1合理情况应该FrameTest 继承JFrame 另外JFrame是不是可以直接 add 控件了 你要看看api
jin_zh 2014-07-18
  • 打赏
  • 举报
回复
试过了,不行,他是继承类,我把整个程序都贴出来吧 package test; import javax.swing.*; import java.awt.*; class FrameTest { JFrame frameObj; public FrameTest() { frameObj=new JFrame("window"); frameObj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frameObj.setVisible(true); frameObj.setSize(600,400); } } class ButtonTest extends FrameTest { JButton buttonObj1; JButton buttonObj2; JButton buttonObj3; JButton buttonObj4; public ButtonTest() { buttonObj1=new JButton("播放"); buttonObj2=new JButton("上一首"); buttonObj3=new JButton("下一首"); buttonObj4=new JButton("暂停"); getContentPane().add("West",buttonObj1); getContentPane().add(buttonObj2); getContentPane().add(buttonObj3); getContentPane().add(buttonObj4); } } class FlowLayoutTest extends ButtonTest { FlowLayoutTest layoutObj; public FlowLayoutTest() { layoutObj=new FlowLayoutTest(); getContentPane().setLayout(layoutObj); } } public class J1_Frame { public static void main(String[] args) { new FlowLayoutTest(); } }

87,995

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧