问题描述
我已经大概实现出来了,但是如果窗口一扩大,label还是在原来设定的地方出来,怎样才能使label出来的地方随JFrame大小而改变?importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.net.URL;publicclassTest4extendsJApplet{privateJLabellabel=newJLabel("欢迎来到Java的世界!");privateTimertimer;publicvoidinit(){setLayout(null);add(label);label.setBounds(300,60,150,40);timer=newTimer(100,newActionListener(){publicvoidactionPerformed(ActionEvente){label.setLocation(label.getLocation().x-5,label.getLocation().y);if(label.getLocation().x+150<=0){label.setBounds(300,60,150,40);timer.restart();}}});timer.setInitialDelay(0);}publicvoidsetlabelsize(intwidth,intheight){label.setBounds(width,height/2,150,40);}publicvoidstart(){timer.start();}publicvoidstop(){timer.stop();}publicstaticvoidmain(String[]arge){JFrameframe=newJFrame("Test4");Test4applet=newTest4();frame.add(applet);applet.start();applet.init();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setSize(300,120);frame.setVisible(true);}}
解决方案
解决方案二:
没人么没人么没人么?