📄 main.java
字号:
/*
* Main.java
*
* Created on 2007年10月14日, 下午8:40
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package huayuan;
import javax.swing.*;
import java.awt.*;
import java.io.*;
/**
*
* @author hzj
*/
class SetPixel extends JPanel
{
Color color;
int radius;
public SetPixel(int x1)
{
color =Color.red;
radius=x1;
}
public void paintComponent(Graphics g)
{
g.setColor(color);
drawLine(g,radius);
}
void drawLine(Graphics g,int rad)
{
// Bresenham算法
int x,y,d;
x=0;y=rad;d=3-2*rad;
while(x<y)
{
g.drawLine(x,y,x,y);
if(d<0)d=d+4*x+6;
else
{
d=d+4*(x-y)+10;
y--;
}
x++;
}
if(x==y)
g.drawLine(x,y,x,y);
}
}
public class Main extends JFrame
{
public Main()
{
super("PixelColor");
int a=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
a=Integer.parseInt(br.readLine());
}
catch(Exception e) {}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(new Rectangle(100,100,300,300));
SetPixel set=new SetPixel(a);
add(set);
}
public static void main(String[] args) {
// TODO code application logic here
Main setPixel=new Main();
setPixel.show();
}
}
//public class Main {
//
// /** Creates a new instance of Main */
// public Main() {
// }
//
// /**
// * @param args the command line arguments
// */
// public static void main(String[] args) {
// // TODO code application logic here
// }
//
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -