当左键单击鼠标时,应该交换彼此水平相邻的颜色,当右键单击时,垂直相邻的颜色应该交换.单击任一按钮时都没有发生任何事情.
有问题的代码:
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import sun.java2d.loops.DrawRect;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class Board extends JPanel implements MouseListener
{
//instance variables
private int width;
private int height;
private Block topLeft;
private Block topRight;
private Block botLeft;
private Block botRight;
public Board() //constructor
{
width = 200;
height = 200;
topLeft=new Block(0,0,width/2-10,height/2-10,Color.RED);
topRight=new Block(width/2,0,width/2-10,height/2-10,Color.GREEN);
botLeft=new Block(0,height/2,width/2-10,height/2-10,Color.BLUE);
botRight=new Block(width/2,height/2,width/2-10,height/2-10,Color.YELLOW);
setBackground(Color.WHITE);
setVisible(true);
//start trapping for mouse clicks
addMouseListener(this);
}
//initialization constructor
public Board(int w, int h) //constructor
{
width = …Run Code Online (Sandbox Code Playgroud) 我在德克萨斯理工大学的编程课上,在上学期学习Python之后,我终于进入了C++课程.当我们今天在课堂上制作一个HelloWorld程序时,我和其他一些人得到了Microsoft Visual Studio 2013告诉我们使用scanf_s而不是scanf,就像教师在他的程序中使用的一样.下面是我的代码.
#include <stdio.h>
int main(){
int i,j;
float x,y;
scanf("input a number: %d %d %f %f", &i, &j, &x, &y);
printf("print numbers a : %d \n",i);
printf("print numbers a : %10.3d \n", i);
printf("print numbers a : %-10.3d", i);
fflush(stdin);
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)