import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Painter extends JFrame{
/**
*
*/
private static final long serialVersionUID = 8160427604782702376L;
CanvasPanel canvas = new CanvasPanel();;
public Painter() {
super("Star");
this.add(canvas);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
new Painter();
}
}
class CanvasPanel extends JPanel implements ActionListener{
/**
*
*/
private static final long serialVersionUID = -4642528854538741028L;
private JButton[] btn = new JButton[4];
private String[] btn_name = {"+", "-", "R", "L"};
private int center_x = 200, center_y = 200, radius = 100, degree = 0;
public CanvasPanel() {
this.setPreferredSize(new Dimension(400, 500));
this.setLayout(null);
for(int i = 0; i < 4; i++) {
btn[i] = new JButton(btn_name[i]);
btn[i].setBounds(160 + i * 60, 425, 50, 50);
btn[i].addActionListener(this);
this.add(btn[i]);
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for(int i = 0; i < 5; i++) {
g.drawLine( (int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i))),
(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i))),
(int) (center_x + radius * Math.sin(Math.toRadians(degree + 72 * i + 144))),
(int) (center_y - radius * Math.cos(Math.toRadians(degree + 72 * i + 144))));
}
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand() == "+") {
if(radius < 200)
radius += 2;
repaint();
} else if(e.getActionCommand() == "-") {
if(radius > 0)
radius -= 2;
repaint();
} else if(e.getActionCommand() == "R") {
degree = (degree + 2) % 360;
repaint();
} else if(e.getActionCommand() == "L") {
degree = (degree - 2) % 360;
repaint();
}
}
}
Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
本回答被网友采纳package nihao;
import javax.swing.JOptionPane;
public class world {
public static void main(String[] args) {
JOptionPane.showMessageDialog(
null,
"mly l love you"
);
System.exit(0);
}
}
Java简单代码?
求一个简单又有趣的JAVA小游戏代码1、System.out.println(猜数字游戏,请输入一个数0到999999,输入-1结束游戏:);inti=sc.nextInt();if(i==-1){break;}count++;if(ir){System.out.print(你猜小了。2、-12-05求大神指点如何用java做扫雷小游戏详细...有源代码吗2011-01-10怎么用Java...
用java编写一下程序,希望能有详细代码和注释,谢谢了
package xiushifu; \/\/创建包 import java.util.*; \/\/加载包 Scanner用到 public class text2 { public static void main(String[] args){ new key(); \/\/创建实例调用key类的构造方法 } } class key \/\/ { private String x = "123456" ; \/\/初始化密码 final static St...
Java求程序代码
按照你的要求编写的Java程序如下 import java.util.Scanner;public class S{ public static void main(String[] args){ int n=5;int[] a=new int[n];System.out.print("请输入"+n+"个正整数:");Scanner sc=new Scanner(System.in);for(int i=0;i<n;i++){ a[i]=sc.nextInt();}...
简单的java代码,求讲解。。
import javax.swing.*;import java.awt.event.*; 引入库 public class Test2 implements ActionListener{ 实现ActionListener JButton button; 定义按钮变量 public static void main(String[] args) { Test2 gui = new Test2(); 定义、实现类 gui.go(); 开始执行、打开界面 } publicvo...
java简单代码小游戏?
5、编写好的java程序(*.java),首先要用javac.exe编译成为字节码文件(*.class),然后使用java.exe来执行。建议你下载一个eclipse,用集成开发环境,这个比较方便。求一个简单的JAVA游戏代码,100行左右,谢谢!下面是一个可能的Java源代码,它包含了一个接口(Shape)和五个类(Circle,Rectangle,Triangle...
求一个简单的Java小游戏的代码
import java.awt.event.*;public class lianliankan implements ActionListener { JFrame mainFrame; \/\/主面板 Container thisContainer;JPanel centerPanel,southPanel,northPanel; \/\/子面板 JButton diamondsButton[][] = new JButton[6][5];\/\/游戏按钮数组 JButton exitButton,resetButton,newlyButton...
求java程序代码
import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPasswordField;import javax.swing.JTextField;\/ 一个简单的Swing窗口,输入内容单击“确定”按钮后...
求简单JAVA程序代码,能操作的,简单的计算器有计算功能+-*\/就行越...
public static void main(String[] args) { String st = "";计算器 j = new 计算器();boolean t = true;while (t) { System.out.print("请输入计算代码:");BufferedReader br = new BufferedReader(new InputStreamReader(System.in));try { st = br.readLine();} catch (IOException ...
用JAVA编一个程序,很基本的,帮忙一下,课堂作业。 1)程序随机分配给客户...
import java.util.Scanner;public class AddTest { public static void main(String args[]){ boolean flag = true;while(flag){ Scanner scanner = new Scanner(System.in);System.out.println("请输入一个1-100的整数");\/\/input 是接收控制台输入的整数 int input = scanner.nextInt();\/\/...
一个简单的JAVA代码,求注释
import java.io.*;\/\/类的功能:接收用户输入的数值x,如果x<50,就打印输出 public class NumberTest{ public static void main(String[] args) throws IOException{ \/\/定义最大的数(和用户输入的数相比较)final int MAX_NUM=50;\/\/字符输入流:用于接收键盘输入 InputStreamReader ir=new InputStream...