在java JFrame中使用AudioClip播放音乐,调用repaint时音乐会停止,是为什么?

在java JFrame中使用AudioClip播放音乐,调用repaint时音乐会停止,是为什么?

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
jframe中repaint问题!!!
为什么frame中调用repaint方法可以擦除原有图画而在jframe中原有图画任然保留呢?jframe中应该如何解决呢?十万分谢谢……
JFrame repaint() 的问题!
//我设置了一个按钮:当被按下时,主窗口的扩大,且在扩大区增加一个文本框,当再次单击按钮时,就变为原来的样子rn//问题:当按钮被按下时,窗口是扩大了,但是没有文本框,只有把窗口最大化后文本框才出现,为什么调用了了repaint()方法还不能rn//发生窗口的重绘,其中了在类中 定义 boolean b=false;rnrnjButton3.addActionListener(new ActionListener()rn rn public void actionPerformed(ActionEvent e) rn if(!b)rn rn setSize(new Dimension(500, 300));rn JTextArea jTextArea5 = new JTextArea();rn contentPane.add(jTextArea5,new XYConstraints(316, 30, 150, 200));rn repaint();rn b=true;rn rn else rn rn b=false;rn setSize(new Dimension(300, 300));rn rn
JFrame的子类调用repaint方法 有关问题
import java.awt.Graphics;rnrnimport javax.swing.JFrame;rnrnpublic class Test extends JFramernrn public Test()rn rn this.setBounds(0, 0, 500, 500);rn new Thread( new Runnable()rn rn @Overridern public void run()rn rn while(true)rn rn Test.this.repaint();rn System.out.println("call repaint");rn try rn Thread.sleep(100);rn catch (InterruptedException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn ).start();rn rn @Overridern public void paint(Graphics g)rn rn super.paint(g);rn System.out.println("call paint");rn rn @Overridern public void update(Graphics g)rn rn System.out.println("call update");rn rnrn public static void main(String[] args) rn rn new Test().setVisible(true);rn rnrnrn这个程序 重写了, update 和paint 起了一个线程每100毫秒掉一次repaint,但是根据输出显示..每次调用repaint 接下来调用的是paint,怎么没掉update啊.. update的原型是这样的吧。。我之前听说应该是先调用update的啊。。
请教关于JFrame里的repaint的调用问题!
那位大哥、大姐救救我,这个程序我已经该了5、6边了,我快承不住了就是每次都能正常rn运行,但是不能按条件显示相应的桌面:rnrn我的程序调用JFrame中的repaint总是没有反应!(一般情况不是调用paint())rn我的程序大体结构如下:rnpublic class Game extends JFramern ....rn public void init()rn .....rn GPanel gPanel=new GPanel(...);rn timer=new Timer(nTime,new MyRun());//创建记时器,调用MyRunrn ....rn gPanel.setVisible(true);rn setVisible(true);rn rn rn public void paint(Graphics g)rn ................rn System.out.println("in game Paint"+ ++pk);rn super.paint(g);rn rn //在这里我加函数update结果还是不正确!!rn // public void update(Graphics g) paint(g); rn //rn ..............rn public class MyRun implements ActionListener //记时器调用的监听器rn rn public void actionPerformed(ActionEvent e)rn rn int direction= snake.getDirection();rn switch(direction)rn case Snake.DOWN :rn if(snake.down())rn System.out.println("in Myrun down down");rn repaint();rn //我怀疑是不是调不到Game中的repaintrn //加了Game.this.repaint();结果还不正确rn //另外加System.out.println(getIgnoreRepaint());rn //结果是false,没问题呀!rn rn .........rn break;rn case Snake.UP :rn if(snake.up())rn System.out.println("in Myrun up upup");rn repaint();rn rn ............... rn break;rn case Snake.LEFT :rn if(snake.left())rn System.out.println("in Myrun left left");rn repaint();rn rn ............... rn break;rn case Snake.RIGHT :rn if(snake.right())rn System.out.println("in Myrun right right");rn repaint();rn rn ...........rn break;rn rnrn rn rn ...........rn rn。。。。。。。。。。。rnrn 另一个类:rn public class GPanel extends JPanelrn ..........rnrn public void paintComponent(Graphics g)rn super.paintComponent(g); rn System.out.println("Gpanel _paintComponent! "+k+"\n");rn //下面是一系列的g.drawImage(...);rn ........rn rnrn rnrn运行的结果(部分)rn...........rnin game Paint1 .rnGpanel _paintComponent! 1 .rnin game Paint2 .rnGpanel _paintComponent! 2 ..........(1)rnin game Paint3 .rnGpanel _paintComponent! 3 . rnin game Paint4 .rnin Myrun 1direction=3rnin Myrun right rightrnin Myrun 2direction=3rnin Myrun right right (2)rnin Myrun 3direction=3rnin Myrun right rightrnin Myrun 4direction=3rn..............rnrn我想请教各位的问题是:rn1、结果(2)显示,在调用repaint()时,似乎Game中的paint()没有响应,why?rn2、就是我运行这个程序时,cpu的占用率93%,我的天呀,我这也是个很小应用程序,虽rn说java耗资源,那不可能这么夸张吧!我想还是我的程序问题?各位大哥、大姐能帮我分rn析why吗?rn3、对结果(1),我的疑问是在程序刚执行的时候,JFrame的是如何调用paint的,调用的时rn间和调用顺序等等。rnrn多谢各位帮忙(能看到这儿我都很感激了)~~~~我真的好烦!!!rn
停止播放音乐
本课程为C语言控制台版贪吃蛇教程
Java repaint()无法调用
import java.awt.* ;rnpublic class Myball rnrn public static void main(String[] args) rn Frame w = new Frame() ;rn w.setSize(1024, 768) ;rn Mypanel mp = new Mypanel() ;rn w.add(mp) ;rn Thread t = new Thread(mp) ;rn t.start() ;rn w.show() ;rnrn rnrnrnrnclass Mypanel extends Panel implements Runnablern int x = 30 ; rn int y = 30 ;rn public void paint(Graphics g)rn rn while(true)rn rn g.setColor(new Color((int)(Math.random()*255),rn (int)(Math.random()*255),rn (int)(Math.random()*255)));rn g.fillOval(x, y, 20, 20) ;rn rn rn rn public void run()rn while(true)rn y ++ ;rn if(y>768)rn y = 0 ;rn rn tryrn Thread.sleep(30);rn catch(Exception e)rn repaint() ;rn rn rnrn rn该程序中小球的位置并不能被重写。repaint并没被调用。不清楚是为什么。麻烦各位指教一下、
为什么播放音乐时自动关机?
MP3和WAV时可正常播放但播放一段时间后(时间不定约半分钟),自动关机。rn系统:Win98。播放软件:winamp,豪杰。声卡:创新的sound pro(很老了,呵呵)rn是系统的问题还是声卡??
【使用AudioClip编的一个播放音乐的小程序,无法正常播放音乐,是哪里的问题啊?】
import java.applet.*;nimport java.awt.*;nimport java.awt.event.*;nimport java.io.File;nimport java.net.MalformedURLException;nimport java.net.URL;nimport javax.swing.*;npublic class t1 extends JAppletn private AudioClip ac;n private JButton jbtPlay,jbtLoop,jbtStop;n public t1() n n setLayout(new GridLayout(1,3));n add(jbtPlay=new JButton("Play"));n add(jbtLoop=new JButton("Loop"));n add(jbtStop=new JButton("Stop"));n URL urlAudio=this.getClass().getResource("music/Gee.mid"); n ac=Applet.newAudioClip(urlAudio);n jbtPlay.addActionListener(new ButtonListener());n jbtLoop.addActionListener(new ButtonListener());n jbtStop.addActionListener(new ButtonListener());n n class ButtonListener implements ActionListenern n public void actionPerformed(ActionEvent e)n n if(e.getSource()==jbtPlay)n ac.play();n else if(e.getSource()==jbtLoop)n ac.loop();n else if(e.getSource()==jbtStop)n ac.stop();n n n public static void main(String[] args) throws MalformedURLException n n JFrame frame = new JFrame();n t1 applate=new t1();n frame.add(applate);n frame.setSize(420,80);n frame.setLocationRelativeTo(null);n frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);n frame.setVisible(true);n n
jComponent中为什么调用repaint不起作用
[code=java]rnpublic class GridPanel extends JPanel rn rn public PicComponent picComponent; rn public GridPanel()rn rn rn rn public void paintPic() throws IOException rn setLayout(new GridLayout(CategoryPanel.Books.size()/3+1,3));rn for(int i = 0;i
为何 AudioClip 是一个类??
我查过 java 的 API 文档,那里明明写着 AudioClip 是 java.applet 里的一个接口!!rnrn唉,这不明摆着捉弄我们这些初学者吗???
播放音乐时的状态条使用
<ProgressBar android:id="@+id/progreso" style="?android:attr/progressBarStyleHorizontal"   public class Player extends Activity implements Runnable, OnClickListener{ private TextVi...
H5播放音乐中途停止
用ServeltOutputStream输出音乐文件,H5前台可以播放音乐,但整首歌曲4分钟,只能播放53秒,然后就停止了。rn求播放完整方法。rnrn控制台日志:rn[code=text]rn信息: A cookie header was received [1500479053] that contained an invalid cookie. That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level.rn[/code]rnrn前台代码:rn[code=html]rn rn[/code]rnrn后台代码:rn[code=java]rn@RequestMapping("/video.do")rn public @ResponseBody void video(String id, HttpServletRequest request, HttpServletResponse response)throws Exceptionrn File file = new File("E:/1.mp3");rn FileInputStream in = new FileInputStream(file);rn BufferedInputStream bin = new BufferedInputStream(in);rn ServletOutputStream out = response.getOutputStream();rn byte[] b = null;rn while(bin.available() >0) rn if(bin.available()>102400) rn b = new byte[102400];rn else rn b = new byte[bin.available()];rn rn bin.read(b, 0, b.length);rn out.write(b, 0, b.length);rn rn b = new byte[bin.available()];rn bin.read(b);rn out.write(b);rn in.close();rn out.flush();rn out.close();rn rn[/code]
java JFrame,组件的调用
我现在情况是,rn写了两个JFrame窗口frame1、frame2,frame1里面有个button btn,按了以后会弹出frame2rn我现在想在frame1的ActionPerformed里面添加个操作,就是在点击了rnbtn后,对窗口2的JTextArea ta进行setText(),这要怎么写呀?rn我在frame1里使用frame2.ta.setText()就报错。。。。
如何停止playsound播放音乐
当按下F1时开始播放,然后按F4结束播放,如何实现啊,我的代码如下,怎么改??rn求各位高手赐教rn rnif(key == GLUT_KEY_F1)rn PlaySound("music/music.wav", NULL, SND_SYNC); rn rn if(key == GLUT_KEY_F4)rn PlaySound(NULL,NULL,0); // 停止播放音乐rn
为什么找不到AudioClip?
AudioClip这个类在哪?protected AudioClip getAudioClip(int id)提示我找不到rnimport dyk1.AudioClip;也没有 (dyk1是工程名)
AudioClip是抽象的问题!
import javax.swing.*;rnimport java.awt.*;rnimport java.awt.event.*;rnimport java.applet.*;rnrnpublic class AudioDemo extends JAppletrnrn private String[] audioFiles="01 爱在离别时.wav","01 不甘寂寞.mp3","01 春天里.mp3",rn "001_Beatles_-_Yesterday.mp3","01 - 如果云知道.mp3","01 main titles.mp3";rn private JComboBox combFilename=new JComboBox(audioFiles);rn private String dirStr="E:/音乐";rn private AudioClip[] audios;rn private AudioClip audioPlay;rn private JButton playButton,loopButton,stopButton;rn rn public void init()rn rn audios=new AudioClip(audioFiles.length);//这里编译时出现错误rn for(int i=0;i
java 怎样只在一个JFrame中调用其他类的Jframe
意思就是只显示一个窗口,例如:rnclass A{JFrame fa;rnbutton b;}rnrnclass B{JFrame fb;}rnrn点击class A的button b时,就在class A的JFrame fa,显示class B的内容rnrn而不是rnnew class Brnfa.setVisible(flase);
关于按钮隐藏和JFrame的repaint()函数
就是一个测试程序,java新手,想做一个游戏开始前的开始按钮。点击以后就会开始游戏,按钮自动隐藏。可是我这个怎么不起作用,另外按钮放到borderlayout布局管理里怎么调整大小。我得repain()函数也不能把之前画的矩形给擦出了。求大神指教,新手···rnimport java.awt.BorderLayout;rnimport java.awt.*;rnimport javax.swing.*;rnimport java.util.Timer;rnimport java.awt.event.*;rnrn/**rn *rn * @author Marn */rnpublic class MyFrame extends JFrame rnrn public int start;//游戏状态 可以不用管没用rnrn private final int wight=500,high=510;//窗口大小rn JPanel p;rn //GUI构件rn public JButton button;rn rn public MyFrame()rn super("TankWarII"); rn p=new JPanel();rn p.setLayout(new FlowLayout());rn start=0;rn rnrn button=new JButton("开始游戏"); rn button.setPreferredSize(new Dimension(120, 50));rn button.addActionListener(new ActionListener()rn @Overridern public void actionPerformed(ActionEvent e)rn start=1;rn button.setVisible(false);rn button.setEnabled(false);rn rn repaint();rn rn rn rn );rn rn this.add(p,BorderLayout.NORTH);rn p.add(button); rn this.setSize(wight, high);rn rn rnrn int i=100;rn public void paint(Graphics g)rn if(start==1)rn g.setColor(Color.red); rn g.fill3DRect(10, 30, i, i, true);rn i--;rn rn rn if(i==0)rn i=0;rn start=0;rn repaint();rn rn rn rn rn rnrnclass aarn public static void main(String arg[])rn MyFrame aa=new MyFrame();rn aa.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn aa.setVisible(true);rn rn rn
为什么IIS是停止的?
我装了系统XP2,然后装IIS,装完之后IIS是停止的,也不能启动.提示(服务没有及时响应启动或控制请求)??????????rnrn高手帮忙
java中的内部类在调用.getClass()时为什么是class java.lang.Class
java中的内部类在调用.getClass()时为什么输出是class java.lang.Class 不应该是内部类本来的类名么?
为什么repaint没有调用paint或update?
[code=Java][/code]import java.awt.*;rnimport javax.swing.*;rnrnpublic class Test implements Runnablern private static BoardPanel boardPanel = new BoardPanel(); rn Test()rn new Thread(this).start();rn rn @Overridern public void run()rn int i = 1;rn while(true)rn tryrn Thread.sleep(30);rn rn catch(InterruptedException e)rn rn boardPanel.repaint();rn System.out.println("Thread run "+(i++));rn rn rn public static void main(String[] args)rn new Test();rn BoardPanel boardPanel = new BoardPanel(); rn JFrame frame = new JFrame();rn frame.add(boardPanel,BorderLayout.CENTER);rn frame.setSize(475,494);rn frame.setResizable(false);rn frame.setVisible(true);rn frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn rnrnclass BoardPanel extends JPanelrn @Overridern public void update(Graphics g)rn paint(g);rn rn int i = 1;rn @Overridern public void paint(Graphics g)rn System.out.println("paint "+(i++));rn rn
Swing:为什么repaint()并没有调用paintComponent方法
这个程序想要画两个小球,一个平抛,一个自由落体。为什么在62行的repaint方法,并没有进入paintComponent()方法中。rn请高手指教!rn[code=Java]rnpackage org.net;rnrnimport javax.swing.*;rnimport java.awt.*;rnimport java.awt.event.*;rnimport java.awt.geom.Ellipse2D;rnpublic class BallFrame extends JFramern JPanel downPanel;rn JButton startButton;rn MyPanel upPanel;rn Ellipse2D.Double d1 ;rn Ellipse2D.Double d2 ;rn long t;rn long begin;rn double x;rn double y;rn public BallFrame()rn setSize(300,400);rn downPanel = new JPanel();rn startButton = new JButton("start");rn startButton.addActionListener(new ActionListener()rn public void actionPerformed(ActionEvent event)rn MyThread t = new MyThread();rn begin = System.currentTimeMillis();rn t.start();rn rn );rn downPanel.add(startButton);rn add(downPanel,BorderLayout.SOUTH);rn upPanel = new MyPanel();rn d1 = new Ellipse2D.Double(0,0,15,15);rn d2 = new Ellipse2D.Double(0,0,15,15);rn upPanel.addBall(d1,d2);rn rn public static void main(String[] args) rn BallFrame f = new BallFrame();rn f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn f.setVisible(true);rn rn class MyPanel extends JPanelrn Ellipse2D.Double d1 ;rn Ellipse2D.Double d2 ;rn public void paintComponent(Graphics g) //???没有被调用rn super.paintComponent(g);rn System.out.println("===进入paint方法===");rn Graphics2D g2 = (Graphics2D)g;rn g2.fill(d1);rn g2.fill(d2);rn rn public void addBall(Ellipse2D.Double d1,Ellipse2D.Double d2)rn this.d1 = d1;rn this.d2 = d2;rn rn rn class MyThread extends Threadrn public void run()rn for(int i=0;i<1000;i++)rn t = (System.currentTimeMillis()-begin)/1000;rn x = 26*t;rn y = 0.5 * 9.8 * Math.pow(t, 2);rn System.out.println(x+":"+y);rn repaint(); //????为什么调用repaint方法不能进入paintComponent方法呢?rn tryrn Thread.sleep(100);rn rn catch(Exception e)rn rn rn rn rn rnrnrn[/code]
如何在JAVA中插入音乐 及 为什么音乐会中断
我用了这样的方法成功的在JAVA中插入了音乐 rn[code=Java] tha=new Thread(new Runnable()rn AudioClip audio=java.applet.Applet.newAudioClip(this.getClass().getResource( "source/begin.wav"));rn public void run()rn audio.loop(); //音乐单独的进程rn );rn tha.run(); rn [/code]rnrn可是在频繁的点击一个必须频繁点击的按钮时经常导致音乐中断 这是为什么 怎么解决?
java中播放音乐的问题
我想在自己做的一个小游戏中添加上背景音乐代码如下:rnAudioClip clip ;rn try rn clip= Applet.newAudioClip(new File("F:\\Java\\mayingshi2\\Maze\\src\\mario.wav").toURL());rn URL a=new File("F:\\Java\\mayingshi2\\Maze\\src\\shui.wav").toURL();rn clip.play();rn catch (MalformedURLException e) rn rn不知道怎么回事,当程序运行的时候,音乐只播放几秒钟,任何就自动停止了。rn这是怎么回事呢?难道是没有把全部的音频流获取过来么?该怎么改?求大家帮帮忙~
关于java的JFrame调用问题
我在主函数创建了一个JFrame对象(f1),然后在该对象里面的一个按钮监听器中又创建了另外一个JFrame对象(f2),在f2中修改f1中的变量之后关闭f2然后怎么实现f1的重画?
repaint没反应,actionPerformed中调用repaint方法画图
在actionPerformed中调用repaint方法画图,点击重绘按钮无反应。只要缩小窗口再放大,新的图形就产生了。怎样才能点击按钮后,自动刷新显示新图形?希望大家指点一下。谢谢了。
java 中播放音乐的问题
//我用的是Eclipse,在里面播放音乐,运行就不行了。歌曲和代码放在一起。rn我用java Applet运行正确,但还是没有声音。rn用 java Bean 就会出错。rn错误如下:rn/*IWAV0054I Applet Playsound1 startedrnException in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionrn at Playsound1.actionPerformed(Playsound1.java:43)rn at java.awt.Button.processActionEvent(Button.java:392)rn at java.awt.Button.processEvent(Button.java:360)rn at java.awt.Component.dispatchEventImpl(Component.java:4413)rn at java.awt.Component.dispatchEvent(Component.java:4243)rn at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)rn at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)rn at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)rn at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)rn at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)*/rnrnimport java.applet.Applet;rnimport java.applet.AudioClip;rnimport java.awt.Button;rnimport java.awt.Choice;rnimport java.awt.event.ActionEvent;rnimport java.awt.event.ActionListener;rnimport java.awt.event.ItemEvent;rnimport java.awt.event.ItemListener;rnrnrnpublic class Playsound1 extends Applet implements ItemListener,ActionListenerrnrn rn rnrnAudioClip mysound;rnChoice select_sound=new Choice();rnButton paly=new Button("play");rnButton loop=new Button("loop");rnButton stop=new Button("stop");rnpublic void init()rn select_sound.addItem("sound1.wav");rn select_sound.addItem("sound2.wav");rn select_sound.addItem("sound3.wav");rn add(select_sound);rn add(paly);rn add(loop);rn add(stop);rn select_sound.addItemListener(this);rn paly.addActionListener(this);rn loop.addActionListener(this);rn stop.addActionListener(this);rn rnrn public void itemStateChanged(ItemEvent e) rn // TODO 自动生成方法存根rn mysound=getAudioClip(getCodeBase(),select_sound.getSelectedItem());rn rnrn public void actionPerformed(ActionEvent e) rn // TODO 自动生成方法存根rn if(e.getSource()==paly)rn mysound.play();rn elsern if(e.getSource()==loop)rn mysound.loop();rn elsern if(e.getSource()==stop)rn mysound.stop();rn rnrnrnrnrn是不是还要安装什么插件,rn
怎样在java中播放音乐?
用JAVA做一个倒计时的程序中,其中有个要求就是在最后要发出声音以做提醒,请问个位高手怎么处理?rnrn在线等.........
求助 java中repaint的问题
我要做的是让一个方块,一直朝着某个方向运动,但是我运用repaint时,他并没有把上几个运动过的方块给擦除掉,还留着,不知道我哪个地方写错了,请大家帮帮忙看看,谢谢了.rnrnimport javax.swing.*;rnimport java.awt.*;rnrnpublic class TankWar extends JFramernrn Tank t=new Tank();rn public void showFrame()rn rn this.setTitle("坦克大战");rn this.setLocation(100,100);rn this.setSize(800,600);rn this.setBackground(Color.green);rn this.setResizable(false);rn this.setDefaultCloseOperation(EXIT_ON_CLOSE);rn this.setVisible(true);rn new Thread(new RepaintThread()).start();rn rn public void paint(Graphics g)rn rn tryrn rn t.drawTank(g);rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rn //用于实现重画线程rn private class RepaintThread implements Runnablern rn public void run()rn rn while(true)rn rn repaint();//这个地方的重画不知道为什么没有把从前绘过的图给擦掉rn // System.out.println("=====");rn tryrn rn Thread.sleep(1000);rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rn rn rn public static void main(String[]args)rn rn TankWar tk=new TankWar();rn Container c=tk.getContentPane(); rn c.setBackground(Color.green);rn tk.showFrame();rn rn rnrnrnclass Tank rnrn private final int WIDTH=30,HEIGHT=20;rn int intX,intY;rn int x,y;rn Tank()rn rn rn Tank(int x,int y)rn rn intX=x;rn intY=y;rn rn public void drawTank(Graphics g)rn rn tryrn rn Color c=g.getColor();rn g.setColor(Color.RED);rn g.fillRect(x+40,y+40,WIDTH,HEIGHT); rn g.setColor(c);rn x+=50;rn y+=5;rn rn catch(Exception e)rn rn e.printStackTrace();rn rn rn rn
调用repaint函数
我想在一个类的递归函数中调用另一个窗口类的repaint函数,但是直接调用根本没执行,调用其他函数又可以。rn请问要怎样才能让递归函数未执行完的情况下调用窗口类的repaint函数实现重画啊???
关于Java中repaint()的问题
问个关于Java中repaint()的问题:rn调用display()时打印出GamePanel's display! 但不显示GamePanel's PrintComponent,也就是System.out.println("GamePanel's PrintComponent")这条语句没有执行,repaint()方法为什么不能调用 printComponent(Graphics g)方法。rn[code=Java]rnimport java.awt.Graphics;rnimport javax.swing.JPanel;rnrnpublic class RepaintDemo rnrn public static void main(String args[])rn rn GamePanel gamepanel = new GamePanel();rn gamepanel.display();rn rnrnrnclass GamePanel extends JPanelrnrn public void display()rn rn System.out.println("GamePanel's display!");rn this.repaint();rn rn rn protected void printComponent(Graphics g) rn // TODO Auto-generated method stubrn System.out.println("GamePanel's PrintComponent"); rn rnrnrn[/code]rnrn
java repaint中参数用法
在awt绘图开发中,经常要用到paint(),repaint(),repaint(x,y,width,height)rn我知道在调用repaint()时候,会触发paint()方法rn我想问下repaint()和repaint(x,y,width,height),这个不带参数和带参数有什么区别rn我感觉,带参数,似乎也传不到paint()中吧rnrn
java中canvas的repaint问题
我在Jbuilder9中写了如下代码(以下只给出其中的代码片段): rnpublic class canvas extends Canvas rnpublic void paint(Graphics g) rn rng.setColor(Color.BLUE); rng.fillRoundRect(100,100,50,50,20,20); rng.drawRoundRect(100,100,50,50,20,20); rn rnpublic void update(Graphics g) rn rnSystem.out.println("Paint"); rn rn rnrnpublic class Frame1 extends JFrame rn...... rnpublic Frame1() rn...... rncanvas can=new canvas(); rncan.setBackground(Color.white); rncan.repaint(); rn...... rn rn不是说repaint要先调用update,再调用paint的么?这里repain怎么不调用update(因为没有执行System.out.println("Paint");)?rn我qq:77658745 需要全部代码的可以q我rn
repaint()不调用paintComponent()
今天写东西的时候遇到了,以前也这样写过,一直是通过的,但是今天突然今天不调用paintComponent(),debug单步确实不进入paintComponent(),这是咋回事rn简化了代码如下:rnpublic class TestR extends JPanel rnrn public void drawMe() rn System.out.println("TestR's drawMe");rn this.repaint();rn rnrn @Overridern protected void paintComponent(Graphics g) rn // TODO Auto-generated method stubrn System.out.println("重新显示成功");rn rnrnrn
调用 repaint() 的问题
我的类从 japplet 继承,在其中添加了 keylistener, 在 keyPressed() 中得到rn每次所按键的名字,然后调用repaint(), 在paint() 中显示所按键的名字,可是好像 repaint() 不能清屏,使每次所显示的字符重叠在一起,请问应该怎么解决呢?rn多谢!
JFrame中remove的使用
JFrame中Remove是怎么使用的啊? 我这个怎么remove不了? rn请高手指点一下,最好说说原因。rn[code=Java]rnpackage com.edu.test;rnrnimport java.awt.BorderLayout;rnimport java.awt.event.ActionEvent;rnimport java.awt.event.ActionListener;rnimport java.net.URL;rnimport java.util.Vector;rnimport javax.swing.Icon;rnimport javax.swing.ImageIcon;rnimport javax.swing.JButton;rnimport javax.swing.JFrame;rnimport javax.swing.JLabel;rnimport javax.swing.JPanel;rnimport javax.swing.JScrollPane;rnimport javax.swing.JTable;rnrnpublic class TestRemove extends JFramern private Vector vec1 = new Vector();rn private Vector vec2 = new Vector();rn private JTable jt= null;rn private JPanel jp_main = null;rn private JPanel jp_center = null;rn private JPanel jp_south = null;rn private JButton jb_ok = null;rn private JButton jb_quit = null;rn private JLabel jl_pic = null;rn private JScrollPane js = null; rn public TestRemove()rn super("测试remove窗体");rn vec2.add("列一");rn vec2.add("列二");rn vec2.add("列三");rn vec2.add("列四");rn vec2.add("列五");rn rn Vector vec3 = new Vector();rn for(int i = 0;i < 5; i++)rn vec3.add(i+"");rn rn for(int i = 0;i < 5; i++)rn vec1.add(vec3);rn rn rn rn public void LanuchFrame()rn jp_main = new JPanel(new BorderLayout());rn jp_center = new JPanel();rn jp_south = new JPanel();rn jt = new JTable(vec1,vec2);rn js = new JScrollPane(jt);rn jp_center.add(js);rn jb_ok = new JButton("显示表格");rn jb_quit = new JButton("显示图片");rn jp_south.add(jb_ok);rn jp_south.add(jb_quit);rn rn /**显示表格*/rn jb_ok.addActionListener(new ActionListener()rn public void actionPerformed(ActionEvent e)rn remove(jt);rn remove(js);rn remove(jp_center);rn jt = new JTable(vec1,vec2);rn js = new JScrollPane(jt);rn jp_center.add(js);rn jp_main.add(jp_center,BorderLayout.CENTER);rn rn );rn rn /**显示图片*/rn jb_quit.addActionListener(new ActionListener()rn public void actionPerformed(ActionEvent e)rn remove(jt);rn remove(js);rn remove(jp_center);rn URL url = TestRemove.class.getResource("chart.jpg");rn Icon icon = new ImageIcon(url);rn jl_pic = new JLabel(icon);rn js = new JScrollPane(jl_pic);rn jp_center.add(js);rn jp_main.add(jp_center,BorderLayout.CENTER);rn rn );rn rn jp_main.add(jp_center,BorderLayout.CENTER);rn jp_main.add(jp_south,BorderLayout.SOUTH);rn this.setContentPane(jp_main);rn this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn this.setLocation(400,400);rn this.pack();rn this.setVisible(true);rn rn public static void main(String[] args) rn new TestRemove().LanuchFrame();rn rnrnrn[/code]
java中JFrame布局
java中JFrame的几种布局,流布局,网格布局,卡片布局,边框布局
repaint()为什么出错
import java.util.*;rnpublic class Y2k rn public static void main(String[] args)rn Timer timer = new Timer();rn rn TimerTask task = new TimerTask()rn public void run()rn //System.out.println("Boom!");rn repaint();rn rn ;rn rn //Calendar c = new GregorianCalendar(2005, Calendar.JANUARY, 1);rn //timer.schedule(task, c.getTime());rn timer.schedule(task, 0, 1000);rn rnrnrn编译的时候:rnjava.lang.Error: Unresolved compilation problem: rn The method repaint() is undefined for the type rnrn at Y2k.main(Y2k.java:22)rnException in thread "main" rn
Java中的Jframe窗体
JFrame窗体的常用方法: 1、setTitle(“”);//设置窗体标题 ,直接输入标题字符串即可 2、setVisible();//设置窗体是否可见,true:可见,false:不可见 3、setDefaultCloseOperation();//设置窗体关闭方式,关闭方式如下(点击窗体上的关闭按钮x): 1. EXIT_ON_CLOSE:关闭窗体,并停止程序 2. ...
applet 中播放音乐时出现问题
[code=Java]import java.applet.Applet;rnimport java.applet.AudioClip;rnimport java.awt.BorderLayout;rnimport java.awt.event.ActionEvent;rnimport java.awt.event.ActionListener;rnrnimport javax.swing.JButton;rnimport javax.swing.JPanel;rnpublic class Audio extends Applet rn private JPanel panel;rn private JButton button;rn private AudioClip sound;rn private boolean play = true;rn public void init() rn panel = new JPanel();rn button = new JButton("Play");rn sound = getAudioClip(getDocumentBase(),"DragonMusic/BG_000.mid");rn panel.setLayout(new BorderLayout());rn panel.add(button, BorderLayout.CENTER);rn button.addActionListener(new JButtonListener()); rn add(panel);rn sound.loop();rn rn public class JButtonListener implements ActionListenerrn public void actionPerformed(ActionEvent event)rn if(event.getSource()==button)rn System.out.println(play);rn if(play) rn sound.stop();rn play = false;rn else rn sound.stop();rn sound.loop();rn play = true;rn rn rn rn rnrn// rnrn[/code]rn这个只是单个音乐 ,play键一按就停 再按就 重放 ,已测试可以实现,rnrn下面我想多个音乐按上下或左右键切换, play键 同样有暂停 播放功能rn可是按上两次后 再按就再也不会出声了 ,rn请高手指教rn[code=Java]import java.awt.*;rnimport java.awt.event.*;rnimport java.applet.*;rnimport javax.swing.*;rnpublic class Study extends Appletrn private static int i=0;rn private JPanel panel;rn private JButton button;rn private JButton buttonUp;rn private JButton buttonDown;rn private JButton buttonLeft;rn private JButton buttonRight;rn private AudioClip backSound[];rn private AudioClip sound;rn public void init()rn panel=new JPanel();rn button=new JButton("Play");rn buttonUp=new JButton("↑");rn buttonDown=new JButton("↓");rn buttonLeft=new JButton("←");rn buttonRight=new JButton("→");rn rn button.addActionListener(new JButtonListener());rn buttonUp.addActionListener(new JButtonListener());rn buttonDown.addActionListener(new JButtonListener());rn buttonLeft.addActionListener(new JButtonListener());rn buttonRight.addActionListener(new JButtonListener());rn rn backSound=new AudioClip[67];rn for(int n=0;n<67;n++)rn if(n/10==0)rn backSound[n]=getAudioClip(getDocumentBase(),"DragonMusic\\BG_00"+n+".mid");rn rn elsern backSound[n]=getAudioClip(getDocumentBase(),"DragonMusic\\BG_0"+n+".mid");rn rn rn sound=backSound[0];rn sound.loop();rn setSize(400,300);rn panel.setLayout(new BorderLayout());rn panel.add(button,BorderLayout.CENTER);rn panel.add(buttonLeft,BorderLayout.WEST);rn panel.add(buttonRight,BorderLayout.EAST);rn panel.add(buttonUp,BorderLayout.NORTH);rn panel.add(buttonDown,BorderLayout.SOUTH);rn add(panel);rn rn private class JButtonListener implements ActionListenerrn public void actionPerformed(ActionEvent event)rn if(event.getSource()==button)rn sound.stop();rn sound=backSound[i];rn sound.loop();rn rn else if(event.getSource()==buttonLeft||event.getSource()==buttonUp)rn sound.stop();rn if(i>0)rn i--;rn sound=backSound[i];rn sound.loop();rn rn elsern i=backSound.length-1;rn sound=backSound[i];rn sound.loop();rn rn rn else if(event.getSource()==buttonRight||event.getSource()==buttonDown)rn sound.stop();rn if(i==backSound.length-1)rn i=0;rn sound=backSound[i];rn sound.loop();rn rn elsern i++;rn sound=backSound[i];rn sound.loop();rn rn rn rn rnrnrn[/code]
相关热词 c++和c#哪个就业率高 c# 批量动态创建控件 c# 模块和程序集的区别 c# gmap 截图 c# 验证码图片生成类 c# 再次尝试 连接失败 c#开发编写规范 c# 压缩图片好麻烦 c#计算数组中的平均值 c#获取路由参数

相似问题

3
Java高级swing编程,求大神Java高级swing编程,怎样去掉图片外边框
2
java在匿名内部类中如何访问外部的变量?
1
Java中如何根据我点击的按钮呈现不同的JTable样式(一个JFrame中)?
1
Java中如何动态修改JFrame的内容?
2
java 如何在jframe并行显示几个别的jframe中的内容
3
java 里面,创建一个新线程的时候,为什么要传入一个runnable的参数呢?下面有代码
2
JFrame中使用JLabel添加背景图片不显示
2
JAVA中在JPanel里调用Graphics实现循环产生动画的问题。
1
JAVA 为什么JFrame中绘图内容一闪而过
1
我想问一下就是监听器都设置好了,为什么面板里面的小球动不了
1
我是JAVA菜鸟,想问问关于JAVA中JFrame和JPanel的问题
2
关于在JFrame中设置背景图片问题。
1
一个JFrame上添加2个JPanel之后,第一个JPanel上的画东西会在第二个JPanel上显示
1
java写的雷霆战机,我想让子弹一直出来怎么办呢,大神们来帮忙啊,最好给出代码+注释
2
java中panel的背景图片总是挡住按钮怎么解决?
2
java界面布局,在jframe中添加多个jdialog
0
新手求解 大神帮忙 java 中JFrame的布局管理器设为CardLayout后分为两页
1
Jframe问题用来创建一个数据库系统
1
Java JFrame窗体中,而不是Java类中,按源中按钮事件行为中 跳至另一个界面出错,一直闪出新的同一个界面
1
初学java,看教材上Swing包和awt包章节里的示例程序时,遇到的关于调用对象方法的一点小问题