java设计电子算盘_电子算盘,求教实现算珠的上拨与下拨

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

这个是我做的全部代码,怎样都实现不了,谁有好想法,点拨点拨

package z4;

import java.awt.BasicStroke;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Toolkit;

import java.awt.event.*;

import javax.swing.*;

public class z4_1 extends JFrame implements MouseListener {

private static final long serialVersionUID = 1L;

int width = Toolkit.getDefaultToolkit().getScreenSize().width;

int height = Toolkit.getDefaultToolkit().getScreenSize().height;

int x = 0;

int y = 0;

int Flag = 0;

int suanZhu[][] = new int[4][4];

int suanZhu1[] = new int[4];

int suanZhu2[] = new int[4];

int suanZhu3[] = new int[4];

int suanZhu4[] = new int[4];

public z4_1() {

this.setTitle(“电子算盘”);

this.setLocation((width – 900) / 2, (height – 500) / 2);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setResizable(false);

this.setSize(900, 500);

this.setVisible(true);

this.addMouseListener(this);

}

public void paint(Graphics g) {

float lineWidth = 3.0f;

((Graphics2D) g).setStroke(new BasicStroke(lineWidth));

// 算盘边界

((Graphics2D) g).drawLine(50, 80, 480, 80);

((Graphics2D) g).drawLine(50, 179, 480, 179);

((Graphics2D) g).drawLine(50, 422, 480, 422);

((Graphics2D) g).drawLine(50, 80, 50, 422);

((Graphics2D) g).drawLine(480, 80, 480, 422);

// 画算珠

g.setColor(Color.ORANGE);

g.fillOval(84, 131, 65, 45);

g.fillOval(183, 131, 65, 45);

g.fillOval(282, 131, 65, 45);

g.fillOval(381, 131, 65, 45);

for (int i = 0; i

for (int j = 0; j

g.fillOval(84 + 99 * i, 230 + 48 * j, 65, 45);

if (Flag == 1) {

if (suanZhu1[i] == 1) {

g.fillOval(84, 182, 65, 45);

g.setColor(Color.WHITE);

g.fillOval(84, 230 + 48 * i, 65, 45);

suanZhu1[i] = 2;

Flag = 0;

} else if (suanZhu1[i] == 2) {

g.setColor(Color.ORANGE);

g.fillOval(84, 230 + 48 * i, 65, 45);

}

} else if (Flag == 2) {

if (suanZhu2[i] == 1) {

g.fillOval(183, 182, 65, 45);

g.setColor(Color.WHITE);

g.fillOval(183, 230 + 48 * i, 65, 45);

suanZhu2[i] = 2;

Flag = 0;

} else if (suanZhu2[i] == 2) {

g.setColor(Color.ORANGE);

g.fillOval(183, 230 + 48 * i, 65, 45);

}

} else if (Flag == 3) {

if (suanZhu3[i] == 1) {

g.fillOval(282, 182, 65, 45);

g.setColor(Color.WHITE);

g.fillOval(282, 230 + 48 * i, 65, 45);

suanZhu3[i] = 2;

Flag = 0;

} else if (suanZhu3[i] == 2) {

g.setColor(Color.ORANGE);

g.fillOval(282, 230 + 48 * i, 65, 45);

}

} else if (Flag == 4) {

if (suanZhu4[i] == 1) {

g.fillOval(381, 182, 65, 45);

g.setColor(Color.WHITE);

g.fillOval(381, 230 + 48 * i, 65, 45);

suanZhu4[i] = 2;

Flag = 0;

} else if (suanZhu4[i] == 2) {

g.setColor(Color.ORANGE);

g.fillOval(381, 230 + 48 * i, 65, 45);

}

}

}

}

}

public static void main(String[] args) {

new z4_1();

}

@Override

public void mouseClicked(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mouseEntered(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mouseExited(MouseEvent arg0) {

// TODO Auto-generated method stub

}

@Override

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

System.out.println(e.getX());

System.out.println(e.getY());

x = e.getX();

y = e.getY();

// 实现点击那个算珠,就上移到最上面,然后该算珠消失,来模拟上拨动

if (x > 84 && y > 230 && x

x = (x – 84) / 99;

y = (y – 230) / 48;

suanZhu1[y] = 1;

Flag = 1;

} else if (x > 183 && y > 230 && x

x = (x – 84) / 99;

y = (y – 230) / 48;

suanZhu2[y] = 1;

Flag = 2;

} else if (x > 282 && y > 230 && x

x = (x – 84) / 99;

y = (y – 230) / 48;

suanZhu3[y] = 1;

Flag = 3;

} else if (x > 381 && y > 230 && x

x = (x – 84) / 99;

y = (y – 230) / 48;

suanZhu4[y] = 1;

Flag = 4;

} else {

JOptionPane.showMessageDialog(this, “请重新点击”);

}

this.repaint();

}

@Override

public void mouseReleased(MouseEvent arg0) {

// TODO Auto-generated method stub

}

}

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览93886 人正在系统学习中 相关资源:珠宝软件金企管家珠宝店ERP系统v2016金店版_金企文库-其它代码类…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年2月1日
下一篇 2021年2月1日

相关推荐