就是java swing编程
实现;界面上有两个单选框:圆圈和正方形四个按牛:上,下,左,右选中哪个图形点方向按牛,哪个图形就能相应移动就这样
请大家帮帮忙好吗?
我的msn:
[email protected]
在线的,请帮帮忙需要3小时内做出来,谢谢
实现;界面上有两个单选框:圆圈和正方形四个按牛:上,下,左,右选中哪个图形点方向按牛,哪个图形就能相应移动就这样
请大家帮帮忙好吗?
我的msn:
[email protected]
在线的,请帮帮忙需要3小时内做出来,谢谢
解决方案 »
- eclipse绑定tomcat
- Date与String之前的转化问题
- 菜鸟系统变量设置问题!!!
- 问一个Java数据结构中的堆栈问题
- 各位前辈,jsp的传递参数是中文时该怎么处理??
- 关于编译时出现的小错误
- java可以管理数据库吗
- 问个低级的问题:在windows里 有 char * strfilename1 =new char[255];strcpy(strfilename1,"C:\\finger2.bmp")的用法,在纯java里怎么写
- 写java用什么工具好,最近小弟用jbuilder3很不顺手。
- Java里至少输入四个整数值,输三个就说他不合法
- 一个JSP标签库问题(在线等。。)
- 访问一个网页,把网页显示在一个jframe中:如访问http://www.csdn.net,就可以在jframe中看到主页,与在浏览器中看到的效果一样。
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D ;import javax.swing.*;
/*
* Created on 2006-2-21
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author IBM
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MoveShape implements ActionListener
{
JFrame mainFrame;
JPanel buttonPanel,radioPanel,downPanel;
RSPanel mainPanel;
JRadioButton roundRB,squareRB;
ButtonGroup group;
JButton left,right;
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
public MoveShape()
{
mainFrame = new JFrame("Բԫ·½");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setBounds(screenWidth / 8, screenHeight / 8,6*screenWidth / 8, 6*screenHeight / 8);
Container contentPane=mainFrame.getContentPane();
mainPanel= new RSPanel(screenWidth/2,screenHeight/2);
contentPane.add(mainPanel,BorderLayout.CENTER);
buttonPanel=new JPanel();
radioPanel= new JPanel();
downPanel= new JPanel();
roundRB = new JRadioButton("Բ");
roundRB.setSelected(true);
squareRB = new JRadioButton("·½");
group=new ButtonGroup();
group.add(roundRB);
group.add(squareRB);
radioPanel.add(roundRB,BorderLayout.WEST);
radioPanel.add(squareRB,BorderLayout.EAST);
downPanel.add(radioPanel,BorderLayout.NORTH);
left= new JButton("<<");
left.addActionListener(this);
right= new JButton(">>");
right.addActionListener(this);
buttonPanel.add(left);
buttonPanel.add(right);
downPanel.add(buttonPanel,BorderLayout.SOUTH);
contentPane.add(downPanel,BorderLayout.SOUTH);
//mainFrame.pack();
mainFrame.setVisible(true);
}
public static void createAndShowGUI()
{
JFrame.setDefaultLookAndFeelDecorated(true);
MoveShape ms=new MoveShape();
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
} /* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent event)
{
// TODO Auto-generated method stub
if(event.getSource()==left)
{
if(roundRB.isSelected())
mainPanel.moveRS(true,true);
else
mainPanel.moveRS(false,true);
}
else if(event.getSource()==right)
{
if(roundRB.isSelected())
mainPanel.moveRS(true,false);
else
mainPanel.moveRS(false,false);
}
}
}
class RSPanel extends JPanel
{
public final int ROUNDY=300,SQUAREY=100,MOVESPEED=20;
int roundCenter,squareCenter,width;
public RSPanel(int r,int s)
{
super();
this.setBounds(0,0,r*2,s*2-200);
roundCenter=r;
squareCenter=r;
width=s;
}
public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
g2.setBackground(Color.BLUE);
super.paintComponent(g);
g2.setColor(Color.BLUE);
g2.fill(new Ellipse2D.Double(roundCenter,ROUNDY,50,50));
g2.setColor(Color.BLUE);
g2.fill(new Rectangle2D.Double(squareCenter,SQUAREY,50,50));
}
public void moveRS(boolean round,boolean left)
{
if(round)
{
if(left)
{
if(roundCenter-MOVESPEED>0)
roundCenter-=MOVESPEED;
else
roundCenter=0;
}
else
{
if(roundCenter+MOVESPEED<width)
roundCenter+=MOVESPEED;
else
roundCenter=width;
}
}
else
{
if(left)
{
if(squareCenter-MOVESPEED>0)
squareCenter-=MOVESPEED;
else
squareCenter=0;
}
else
{
if(squareCenter+MOVESPEED<width)
squareCenter+=MOVESPEED;
else
squareCenter=width;
}
}
this.paint(this.getGraphics());
}
}数字没有控制好,