关与线程的问题 1个面板上放6个按钮 每行3个 共2行 想让它们顺时针方向转 怎么办??在线等 急! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 定时repaint()吧,时间由spleep(time),time 控制. void setButtonPosition(){//按照顺时针顺序,依次放6个按钮}//将JButton放入一个列表中LinkedList<JButton> buttons=new LinkedList<JButton>();buttons.add(new JButton("A"));...while(true){ //将最后一个按钮提到一个的位置 buttons.addFirst(buttons.removeLast()); //刷新按钮位置 setButtonPosition();} 按钮不用转,上面的标签名变就ok啦,用timer触发事件 请高手出招!!!我不行了整了一天就整了一半import java.awt.event.*;import java.awt.*;import javax.swing.*;public class MymianJFrame extends JFrame implements Runnable { JMenuBar jmb = new JMenuBar(); JMenu jmu = new JMenu("工具"); JMenuItem riliItem = new JMenuItem("日历"); JMenuItem exitItem = new JMenuItem("退出"); JLabel threadLabel = new JLabel(); static Thread thread,threadjbt; int i=0,ax=240,ay=70,bx=510,by=70,cx=510,cy=340,dx=240,dy=340; JLabel tuLabel = new JLabel(); JLabel jieshaoLabel = new JLabel("系统介绍"); JButton peicanjbt = new JButton("营养配餐"); JButton caipujbt = new JButton("菜谱设置"); JButton chengfenjbt = new JButton("营养成分"); JButton cesuanJbt = new JButton("营养分析"); Container con; public MymianJFrame() { con = this.getContentPane(); this.setTitle("营养配餐系统"); this.setJMenuBar(jmb); jmb.add(jmu); jmu.add(riliItem); jmu.add(exitItem); jmu.setFont(new Font("新宋体", Font.PLAIN, 18)); riliItem.setFont(new Font("新宋体", Font.PLAIN, 18)); exitItem.setFont(new Font("新宋体", Font.PLAIN, 18)); tuLabel.setBounds(new java.awt.Rectangle(343, 137, 159, 174)); tuLabel.setBackground(Color.PINK); jieshaoLabel.setBounds(new java.awt.Rectangle(0, 50, 200, 350)); jieshaoLabel.setText("系统介绍"); threadLabel.setBounds(new java.awt.Rectangle(0, 0, 650, 50)); threadLabel.setText("欢迎使用营养配餐系统"); threadLabel.setFont(new Font("新宋体", Font.PLAIN, 28)); peicanjbt.setBounds(new java.awt.Rectangle(240, 70, 100, 40)); chengfenjbt.setBounds(new java.awt.Rectangle(240, 340, 100, 40)); cesuanJbt.setBounds(new java.awt.Rectangle(510, 340, 100, 40)); caipujbt.setBounds(new java.awt.Rectangle(510, 70, 100, 40)); peicanjbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16)); chengfenjbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16)); cesuanJbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16)); caipujbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16)); con.setLayout(null); con.setBackground(Color.YELLOW); con.add(threadLabel); con.add(tuLabel); con.add(jieshaoLabel); con.add(peicanjbt); con.add(caipujbt); con.add(chengfenjbt); con.add(cesuanJbt); thread = new Thread(this); thread.start(); threadjbt=new Thread(this); threadjbt.start(); Icon io = new ImageIcon(".\\2.jpg"); tuLabel.setIcon(io); this.setBounds(new java.awt.Rectangle(200, 150, 650, 450)); // 退出事件 this.setDefaultCloseOperation(0); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { String str = "如果选择确定将要退出本系统。"; if (JOptionPane.showConfirmDialog(null, str + "\n" + "确定要退出吗?", "退出提示", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) == 0) { System.exit(0); } } }); this.setVisible(true); } public static void main(String[] args) { new MymianJFrame(); } public void run() { for(;;) { i += 5; threadLabel.setBounds(i, 0, 650, 50); threadLabel.setText("欢迎使用营养配餐系统"); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } if (i > 360) { while (i != 0) { i -= 5; threadLabel.setBounds(i, 0, 650, 50); threadLabel.setText("欢迎使用营养配餐系统"); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } // int i=0,ax=240,ay=70,bx=510,by=70,cx=510,cy=340,dx=240,dy=340; while(true){ //前两个第一步 ax += 5;by+=5; peicanjbt.setBounds(new java.awt.Rectangle(ax, 70, 100, 40)); caipujbt.setBounds(new java.awt.Rectangle(510, by, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } //前两个第二步 if (ax == 510) { while(ay!=340){ ay += 5;bx-=5; peicanjbt.setBounds(new java.awt.Rectangle(510, ay, 100, 40)); caipujbt.setBounds(new java.awt.Rectangle(bx, 340, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } //前两个按钮第三步 if (ay == 340) { while(ax!=240){ ax -= 5;by-=5; peicanjbt.setBounds(new java.awt.Rectangle(ax, 340, 100, 40)); caipujbt.setBounds(new java.awt.Rectangle(240, by, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } //前两个第四步 if (ax == 240) { while(ay!=70){ ay -= 5; bx+=5; peicanjbt.setBounds(new java.awt.Rectangle(240, ay, 100, 40)); caipujbt.setBounds(new java.awt.Rectangle(bx, 70, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } //后两个第一步 while(cy!=340){ cx-=5;dy-=5; chengfenjbt.setBounds(new java.awt.Rectangle(240, dy, 100, 40)); cesuanJbt.setBounds(new java.awt.Rectangle(cx, 340, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } //后两个第二步 if(cx==240){ while(cy!=70){ cy-=5;dx+=5; chengfenjbt.setBounds(new java.awt.Rectangle(dx, 340, 100, 40)); cesuanJbt.setBounds(new java.awt.Rectangle(510,cy, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } //后两个第三步 if(cy==70){ while(cx!=510){ cx+=5;dy+=5; chengfenjbt.setBounds(new java.awt.Rectangle(510, dy, 100, 40)); cesuanJbt.setBounds(new java.awt.Rectangle(cx, 70, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } //后两个第四步 if(cx==510){ while(cy!=340){ cy+=5;dx-=5; chengfenjbt.setBounds(new java.awt.Rectangle(dx, 340, 100, 40)); cesuanJbt.setBounds(new java.awt.Rectangle(510, cy, 100, 40)); try { thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } } } } }} 关于DataInputStream中readUTF()的返回值疑问??? java线程的运行(很简单的,帮下忙) 数据库中如何比较datetime类型中的大小 关于socket通信问题 关于局域网通信程序的消息处理问题. 看到那么多jsp的书,不知道该买什么了,该怎么学了,大大帮忙下吧.- -# 对于JAVA初始化的一个疑问??高手进来看看?? 请大家看看这个程序 关于SWT中的table 用sun one studio,从java的tutorial下下来的程序,怎么还会有出错提示??? 如何从文件中读入一行字符串 为什么就不能输出汉字呢?
{
//按照顺时针顺序,依次放6个按钮
}//将JButton放入一个列表中
LinkedList<JButton> buttons=new LinkedList<JButton>();
buttons.add(new JButton("A"));
...while(true)
{
//将最后一个按钮提到一个的位置
buttons.addFirst(buttons.removeLast());
//刷新按钮位置
setButtonPosition();
}
我不行了整了一天就整了一半
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;public class MymianJFrame extends JFrame implements Runnable {
JMenuBar jmb = new JMenuBar(); JMenu jmu = new JMenu("工具"); JMenuItem riliItem = new JMenuItem("日历"); JMenuItem exitItem = new JMenuItem("退出"); JLabel threadLabel = new JLabel(); static Thread thread,threadjbt;
int i=0,ax=240,ay=70,bx=510,by=70,cx=510,cy=340,dx=240,dy=340; JLabel tuLabel = new JLabel(); JLabel jieshaoLabel = new JLabel("系统介绍"); JButton peicanjbt = new JButton("营养配餐"); JButton caipujbt = new JButton("菜谱设置"); JButton chengfenjbt = new JButton("营养成分"); JButton cesuanJbt = new JButton("营养分析"); Container con; public MymianJFrame() {
con = this.getContentPane();
this.setTitle("营养配餐系统");
this.setJMenuBar(jmb); jmb.add(jmu);
jmu.add(riliItem);
jmu.add(exitItem); jmu.setFont(new Font("新宋体", Font.PLAIN, 18));
riliItem.setFont(new Font("新宋体", Font.PLAIN, 18));
exitItem.setFont(new Font("新宋体", Font.PLAIN, 18)); tuLabel.setBounds(new java.awt.Rectangle(343, 137, 159, 174));
tuLabel.setBackground(Color.PINK); jieshaoLabel.setBounds(new java.awt.Rectangle(0, 50, 200, 350));
jieshaoLabel.setText("系统介绍"); threadLabel.setBounds(new java.awt.Rectangle(0, 0, 650, 50));
threadLabel.setText("欢迎使用营养配餐系统");
threadLabel.setFont(new Font("新宋体", Font.PLAIN, 28)); peicanjbt.setBounds(new java.awt.Rectangle(240, 70, 100, 40));
chengfenjbt.setBounds(new java.awt.Rectangle(240, 340, 100, 40));
cesuanJbt.setBounds(new java.awt.Rectangle(510, 340, 100, 40));
caipujbt.setBounds(new java.awt.Rectangle(510, 70, 100, 40)); peicanjbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16));
chengfenjbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16));
cesuanJbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16));
caipujbt.setFont(new java.awt.Font("新宋体", java.awt.Font.PLAIN, 16)); con.setLayout(null);
con.setBackground(Color.YELLOW); con.add(threadLabel);
con.add(tuLabel);
con.add(jieshaoLabel); con.add(peicanjbt);
con.add(caipujbt);
con.add(chengfenjbt);
con.add(cesuanJbt); thread = new Thread(this);
thread.start();
threadjbt=new Thread(this);
threadjbt.start(); Icon io = new ImageIcon(".\\2.jpg");
tuLabel.setIcon(io);
this.setBounds(new java.awt.Rectangle(200, 150, 650, 450));
// 退出事件
this.setDefaultCloseOperation(0);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
String str = "如果选择确定将要退出本系统。";
if (JOptionPane.showConfirmDialog(null, str + "\n" + "确定要退出吗?",
"退出提示", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE) == 0) {
System.exit(0);
}
}
});
this.setVisible(true);
} public static void main(String[] args) {
new MymianJFrame();
} public void run() {
for(;;) {
i += 5;
threadLabel.setBounds(i, 0, 650, 50);
threadLabel.setText("欢迎使用营养配餐系统");
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (i > 360) {
while (i != 0) {
i -= 5;
threadLabel.setBounds(i, 0, 650, 50);
threadLabel.setText("欢迎使用营养配餐系统");
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
// int i=0,ax=240,ay=70,bx=510,by=70,cx=510,cy=340,dx=240,dy=340;
while(true){
//前两个第一步
ax += 5;by+=5;
peicanjbt.setBounds(new java.awt.Rectangle(ax, 70, 100, 40));
caipujbt.setBounds(new java.awt.Rectangle(510, by, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
//前两个第二步
if (ax == 510) {
while(ay!=340){
ay += 5;bx-=5;
peicanjbt.setBounds(new java.awt.Rectangle(510, ay, 100, 40));
caipujbt.setBounds(new java.awt.Rectangle(bx, 340, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//前两个按钮第三步
if (ay == 340) {
while(ax!=240){
ax -= 5;by-=5;
peicanjbt.setBounds(new java.awt.Rectangle(ax, 340, 100, 40));
caipujbt.setBounds(new java.awt.Rectangle(240, by, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//前两个第四步
if (ax == 240) {
while(ay!=70){
ay -= 5;
bx+=5;
peicanjbt.setBounds(new java.awt.Rectangle(240, ay, 100, 40));
caipujbt.setBounds(new java.awt.Rectangle(bx, 70, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//后两个第一步
while(cy!=340){
cx-=5;dy-=5;
chengfenjbt.setBounds(new java.awt.Rectangle(240, dy, 100, 40));
cesuanJbt.setBounds(new java.awt.Rectangle(cx, 340, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//后两个第二步
if(cx==240){
while(cy!=70){
cy-=5;dx+=5;
chengfenjbt.setBounds(new java.awt.Rectangle(dx, 340, 100, 40));
cesuanJbt.setBounds(new java.awt.Rectangle(510,cy, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//后两个第三步
if(cy==70){
while(cx!=510){
cx+=5;dy+=5;
chengfenjbt.setBounds(new java.awt.Rectangle(510, dy, 100, 40));
cesuanJbt.setBounds(new java.awt.Rectangle(cx, 70, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
//后两个第四步
if(cx==510){
while(cy!=340){
cy+=5;dx-=5;
chengfenjbt.setBounds(new java.awt.Rectangle(dx, 340, 100, 40));
cesuanJbt.setBounds(new java.awt.Rectangle(510, cy, 100, 40));
try {
thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}}