问题描述
最近在看Java核心技术卷1。里面的程序范例有的没有main函数,该如何运行呢?我用的是eclipse。范例:packageplaf;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.SwingUtilities;importjavax.swing.UIManager;/***Aframewithabuttonpanelforchanginglook-and-feel*/publicclassPlafFrameextendsJFrame{privateJPanelbuttonPanel;publicPlafFrame(){buttonPanel=newJPanel();UIManager.LookAndFeelInfo[]infos=UIManager.getInstalledLookAndFeels();for(UIManager.LookAndFeelInfoinfo:infos)makeButton(info.getName(),info.getClassName());add(buttonPanel);pack();}/***makesabuttontochangethepluggablelook-and-feel*@paramnamethebuttonname*@paramplafNamethenameofthelook-and-feelclass*/voidmakeButton(Stringname,finalStringplafName){//addbuttontopanelJButtonbutton=newJButton(name);buttonPanel.add(button);//setbuttonactionbutton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){//buttonaction:switchtothenewlook-and-feeltry{UIManager.setLookAndFeel(plafName);SwingUtilities.updateComponentTreeUI(PlafFrame.this);pack();}catch(Exceptione){e.printStackTrace();}}});}}
解决方案
解决方案二:
junit或者自己写main函数调用
解决方案三:
junit怎么用呢?
解决方案四:
引用2楼licwang13的回复:
junit怎么用呢?
网上很多,给个参考地址
解决方案五:
是否是applet应用呢,applet小程序是不需要main方法的
解决方案六:
引用4楼magi1201的回复:
是否是applet应用呢,applet小程序是不需要main方法的
能否给一个具体的解决方法。谢谢
解决方案七:
引用3楼shixitong的回复:
Quote: 引用2楼licwang13的回复:
junit怎么用呢?网上很多,给个参考地址
我按照网上的案例操作了一下,还是不行
解决方案八:
引用5楼licwang13的回复:
Quote: 引用4楼magi1201的回复:
是否是applet应用呢,applet小程序是不需要main方法的能否给一个具体的解决方法。谢谢
给你个建议,不要学习swing,awt,还有applet。java中这些东西实际中极少用到,基本不用,用到时再学习这些东西,我都没学过,web里面都不用的
解决方案九:
junit
解决方案十:
简单点自己写个main函数,然后new一个PlafFrame,想运行那个方法就调用那个方法
解决方案十一:
publicstaticvoidmain(String[]args){PlafFrameframe=newPlafFrame();}
解决方案十二:
引用8楼hjq2013的回复:
junit
具体怎么操作,能具体说一下吗?谢谢
解决方案十三:
packageplaf;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.SwingUtilities;importjavax.swing.UIManager;/***Aframewithabuttonpanelforchanginglook-and-feel*/publicclassPlafFrameextendsJFrame{privateJPanelbuttonPanel;publicPlafFrame(){buttonPanel=newJPanel();UIManager.LookAndFeelInfo[]infos=UIManager.getInstalledLookAndFeels();for(UIManager.LookAndFeelInfoinfo:infos)makeButton(info.getName(),info.getClassName());add(buttonPanel);pack();}/***makesabuttontochangethepluggablelook-and-feel*@paramnamethebuttonname*@paramplafNamethenameofthelook-and-feelclass*/voidmakeButton(Stringname,finalStringplafName){//addbuttontopanelJButtonbutton=newJButton(name);buttonPanel.add(button);//setbuttonactionbutton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){//buttonaction:switchtothenewlook-and-feeltry{UIManager.setLookAndFeel(plafName);SwingUtilities.updateComponentTreeUI(PlafFrame.this);pack();}catch(Exceptione){e.printStackTrace();}}});}}
解决方案十四:
[code=javapackageplaf;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.SwingUtilities;importjavax.swing.UIManager;/***Aframewithabuttonpanelforchanginglook-and-feel*/publicclassPlafFrameextendsJFrame{privateJPanelbuttonPanel;publicPlafFrame(){buttonPanel=newJPanel();UIManager.LookAndFeelInfo[]infos=UIManager.getInstalledLookAndFeels();for(UIManager.LookAndFeelInfoinfo:infos)makeButton(info.getName(),info.getClassName());add(buttonPanel);pack();}/***makesabuttontochangethepluggablelook-and-feel*@paramnamethebuttonname*@paramplafNamethenameofthelook-and-feelclass*/voidmakeButton(Stringname,finalStringplafName){//addbuttontopanelJButtonbutton=newJButton(name);buttonPanel.add(button);//setbuttonactionbutton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){//buttonaction:switchtothenewlook-and-feeltry{UIManager.setLookAndFeel(plafName);SwingUtilities.updateComponentTreeUI(PlafFrame.this);pack();}catch(Exceptione){e.printStackTrace();}}});}}][/code]
解决方案十五:
引用11楼licwang13的回复:
Quote: 引用8楼hjq2013的回复:
junit具体怎么操作,能具体说一下吗?谢谢
添加jUnit依赖包,之后建个类,用@Before,@Test,@After去注解三个方法你试试,每个方法你都system.out测试下
解决方案:
packageplaf;publicclassOperate{publicstaticvoidmain(String[]avgs){PlafFrameframe=newPlafFrame();}}
解决方案:
[code=java][packageplaf;publicclassOperate{publicstaticvoidmain(String[]avgs){PlafFrameframe=newPlafFrame();}}]
解决方案:
[code=java][/packageplaf;publicclassOperate{publicstaticvoidmain(String[]avgs){PlafFrameframe=newPlafFrame();}}]