设置jlabel在jframe中的位置 我现在要用java2d做一个东西。利用一个相当与计时器的东西控制一个图片的位置的变化,图片放在jlabel中。我尝试了很多方法,对于它的位置调节都没用,有人说需要调用它的父窗体的方法(是这样的吗)怎么实现啊。总觉得用java编界面没有用vb好用,vb中可以任意调整大小和位置,java为何不那么做,总觉得不解。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 setBounds(x,y,width,height) 比 VB 牛多了 就是 java 比vb要强大多了 import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import javax.swing.border.*;import javax.swing.Icon;public class MoveLabel extends JFrame{ static int x=0; static int y=0; static JLabel label=new JLabel(); public MoveLabel(){ this.setSize(new Dimension(400,300)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.getContentPane().setLayout(null); this.setVisible(true); label.setIcon(new ImageIcon(getClass().getResource("images/boy2-6.gif"))); } public static void main(String[] args){ MoveLabel win=new MoveLabel(); win.getContentPane().add(label); javax.swing.Timer t=new javax.swing.Timer(1000,new ActionListener() { public void actionPerformed(ActionEvent event) { label.setBounds(x++ ,y++,30,30); } } ); t.start(); } } setBounds()不好使,我还用过了setlocation(),我还在netbean中尝试了直接创建一个jframe然后调节属性也不管用,在属性的中初始化后代码中加入setBounds()和setlocation()也不好使。冷月我用你的程序编译执行了,可是什么都没有(连图片也没显示,图片的名字我改了)。 java里面容器的几个问题。。 急求解 把程序放在后台跑,就一定要 extends Thread 吗? 请教FTP 服务器的一个问题 求 SQL Server jar包的 说明文档 -_-||| 如何写文件中的指定一行??? 求解内存 我的 JDK1.3装在windows98上不能用 (在其他机器上可以) APPLET如何放在HTM中? 请教关于JVM设置的问题 如何在servlet中显示图片 jsp中session 的问题,比较难,请教高手
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.Icon;public class MoveLabel extends JFrame{
static int x=0;
static int y=0;
static JLabel label=new JLabel();
public MoveLabel(){
this.setSize(new Dimension(400,300));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setLayout(null);
this.setVisible(true);
label.setIcon(new ImageIcon(getClass().getResource("images/boy2-6.gif")));
} public static void main(String[] args){
MoveLabel win=new MoveLabel();
win.getContentPane().add(label); javax.swing.Timer t=new javax.swing.Timer(1000,new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
label.setBounds(x++ ,y++,30,30);
}
}
);
t.start();
}
}