有更好的算法吗?
// please use jbuilder to run it.
import java.awt.*;
import java.util.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class Chess extends JPanel {
static final int SIZE=19;
public Chess(){
super();
setBackground(Color.pink);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().setLayout(new XYLayout());
f.getContentPane().add(new Chess(),new XYConstraints(25, 25, 350, 350));
f.setSize(400,400);
f.pack();
f.setVisible(true);
}
public void drawAxis(Graphics g) {
int W = getWidth(); int H = getHeight();
g.setColor(Color.gray);
for(int i = 0; i <= SIZE+1; i++){
int h = (int)(i*H/(SIZE+1));
int w = (int)(i*W/(SIZE+1));
if( i%2 == 1 ){
g.fillRect((int)(W/(SIZE+1)),h,W-(int)(W/(SIZE+1)),(int)(H/(SIZE+1)));
}
}
boolean up = true;
int w0 = (int)(W/(SIZE+1));
g.setColor(Color.lightGray);
for(int i = 0; i <= SIZE+1; i++){
int w = (int)(i*W/(SIZE+1));
if( i%2 == 1 ){
up = (i/2) % 2 == 0;
int h = 1;
int l = up?2:3;
while(h < SIZE+1) {
if(up) {
g.fillRect(w,(int)(h*H/(SIZE+1)),
w0,(int)(l*H/(SIZE+1)));
h +=l;
l = 3;
}else
h ++;
up = !up;
}
}
}
}
public void paint(Graphics g){
super.paint(g);
drawAxis(g);
}
}
import java.awt.*;
import java.util.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
public class Chess extends JPanel {
static final int SIZE=19;
public Chess(){
super();
setBackground(Color.pink);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.getContentPane().setLayout(new XYLayout());
f.getContentPane().add(new Chess(),new XYConstraints(25, 25, 350, 350));
f.setSize(400,400);
f.pack();
f.setVisible(true);
}
public void drawAxis(Graphics g) {
int W = getWidth(); int H = getHeight();
g.setColor(Color.gray);
for(int i = 0; i <= SIZE+1; i++){
int h = (int)(i*H/(SIZE+1));
int w = (int)(i*W/(SIZE+1));
if( i%2 == 1 ){
g.fillRect((int)(W/(SIZE+1)),h,W-(int)(W/(SIZE+1)),(int)(H/(SIZE+1)));
}
}
boolean up = true;
int w0 = (int)(W/(SIZE+1));
g.setColor(Color.lightGray);
for(int i = 0; i <= SIZE+1; i++){
int w = (int)(i*W/(SIZE+1));
if( i%2 == 1 ){
up = (i/2) % 2 == 0;
int h = 1;
int l = up?2:3;
while(h < SIZE+1) {
if(up) {
g.fillRect(w,(int)(h*H/(SIZE+1)),
w0,(int)(l*H/(SIZE+1)));
h +=l;
l = 3;
}else
h ++;
up = !up;
}
}
}
}
public void paint(Graphics g){
super.paint(g);
drawAxis(g);
}
}
...全文
相关推荐
如何通俗的解释机器学习的10大算法?.pdf
在《如何通俗的解释机器学习的10大算法?》这份PDF文档中,作者试图以简单易懂的方式介绍机器学习领域的核心算法,以帮助读者更好地理解和应用这些技术。以下是关于10大算法的详细解读:1. 逻辑回归:
一种基于小波理论的LMS算法研究 小波理论 LMS算法
#### 5?00?@算法5?00?@算法是指Mallat的小波多分辨率分析算法,它在小波分析中扮演着类似快速傅里叶变换在傅里叶分析中的角色。
fsp流水车间调度_流水车间调度_遗传算法FSP_遗传算法_M?n_fsp
通过理解和应用其中的方法,我们可以更好地解决实际生产环境中的调度问题,提高生产效率。
leetcode算法题主函数如何写-leetcode:leetcode刷题--经典算法集合
leetcode算法题主函数如何写算法导论算法分析|渐进分析给出两个任务的算法,我们如何找到哪一个更好?通常对于我们来说,一个最简单的方法是实现这两种算法,在计算中运行两个程序以获得不同的输入,并查看
字符串模式匹配的朴素算法和通配符扩展算法
通过深入学习和实践这两种算法,我们可以更好地理解和解决实际的文本处理问题。


Java SE
