java旋转代码怎样写 java实现图形的旋转

请教一下,Java线程让图片一直旋转的问题

你开一个线程改变坐标,在新线程里repaint,在paint方法里画图,事件监听,paint,paintComponent等这些方法都是gui线程,不能执行耗时任务,更不能放个死循环进去。

成都创新互联从2013年开始,先为岳阳县等服务建站,岳阳县等地企业,进行企业商务咨询服务。为岳阳县企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

java如何实现图片拖动,放大缩小,旋转。

这个只是实现了移动,你参考以下吧 !

public class MoveImage {

static int x,y;

private static int num=0;

private static Icon icon=null;

public static void main(String[] args) throws Exception{

JFrame f = new JFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.getContentPane().setLayout(null);//这个要设置成 null

//图片

icon = new ImageIcon("d:/test.gif");//d:/test.gif本地一张图片

JLabel l = new JLabel(icon); //创建具有指定图像的 JLabel 实例。

l.setSize(icon.getIconWidth(),icon.getIconHeight());//设置面板的宽度和高度

l.setBorder(BorderFactory.createLineBorder(Color.red));//给图片加上红色外框

f.getContentPane().add(l);

f.setSize(900,700);

f.setVisible(true);

l.addMouseListener(new MouseAdapter(){

public void mousePressed(MouseEvent e){

x=e.getX();

y=e.getY();

}

});

l.addMouseMotionListener(new MouseMotionListener(){

public void mouseDragged(MouseEvent e) {

JLabel l = (JLabel)e.getSource();

l.setLocation(l.getX()+e.getX()-x,l.getY()+e.getY()-y);

}

public void mouseMoved(MouseEvent e) {}

});

}

求一个Java 代码~~高手请进

import java.awt.*;

import javax.swing.*;

import javax.swing.Timer;

import java.awt.event.*;

import java.util.*;

public class HuaTu extends JComponent implements ActionListener{

JButton jb=new JButton("开始");

Timer timer=new Timer(100,this); //没0.1秒旋转一次

static double X=0.0,sin,cos,sin2,cos2,sin3,cos3;

double r=200/(Math.sqrt(3));

int x1,x2,x3,y1,y2,y3;

public void showGui(){

JFrame f = new JFrame("正三角形逆时针旋转");

jb.setBounds(400,100,60,30);

jb.addActionListener(this);

f.add(jb);

f.setSize(500,500);

JComponent jc = new HuaTu();

f.add(jc);

f.setVisible(true);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent ae) {

Graphics g = getGraphics();

if (ae.getSource().equals(jb)) { //点击按钮

if (!timer.isRunning()) {

jb.setText("暂停");

timer.start();

} else {

timer.stop();

jb.setText("继续");

}

}

else {

X=X+5; //每次旋转5度

}

}

public void paint(Graphics g) {

sin=Math.sin(Math.PI*(X/180.0));

cos=Math.cos(Math.PI*(X/180.0));

sin2=Math.sin(Math.PI*((120+X)/180.0));

cos2=Math.cos(Math.PI*((120+X)/180.0));

sin3=Math.sin(Math.PI*((240+X)/180.0));

cos3=Math.cos(Math.PI*((240+X)/180.0));

x1=(int)(200-r*sin);

y1=(int)(50+r*(1-cos));

x2=(int)(200-r*sin2);

y2=(int)(50+r*(1-cos2));

x3=(int)(200-r*sin3);

y3=(int)(50+r*(1-cos3));

g.setColor(Color.red);

g.drawLine(x1,y1,x2,y2);

g.drawLine(x1,y1,x3,y3);

g.drawLine(x2,y2,x3,y3);

repaint();

}

public static void main(String args[]) {

HuaTu hu=new HuaTu();

hu.showGui();

}

}

java物体旋转

这个不要太简单啊,你把蛤蟆当做一个个对象(各种颜色)。申明一个二维数组,里面放不同的对象。移动后,你可以取得当前的横纵坐标。然后周围的坐标也知道,根据坐标取出数组里面的对象,看看周围有没有三个一样的。然后在做后续处理

如何使一个三行三列的数组顺时针旋转90度,使用java语言!非常感谢啊

public static void main(String[] args)

{

int[][] numbers={

{1,2,3},

{4,5,6},

{7,8,9}

};

int[][] newnum=new int[3][3];

for(int i=0;i3;i++){

for(int j=0;j3;j++){

newnum[i][j]=numbers[2-j][i];

System.out.println(newnum[i][j]);

}

}

}

Java题目:请任意输入一个整数,如12345,将其颠倒输出为54321。 该如何编写相应的代码?

代码如下:

public class App {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int number = scanner.nextInt();

int result = 0;

while (number % 10 != 0) {

result = result * 10 + number % 10;

number /= 10;

}

System.out.println(result);

}

}

运行结果:


当前标题:java旋转代码怎样写 java实现图形的旋转
文章来源:http://bzwzjz.com/article/dooiohh.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设 成都做网站建设公司 成都营销网站制作 网站建设公司 网站建设方案 成都网站设计制作公司 成都网站设计 成都网站建设公司 成都网站设计 外贸网站建设 成都响应式网站建设公司 攀枝花网站设计 网站制作 重庆网站制作 移动网站建设 达州网站设计 网站建设 成都网站建设 营销型网站建设 LED网站设计方案 做网站设计 成都网站建设