「java空开」java开关按钮
本篇文章给大家谈谈java空开,以及java开关按钮对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java编写中 怎么使图中的两个三角中间 空开
输出时,加空格。如 System.out.println("*** ***"),自己计算好空格位置就好了。
或者在原有逻辑基础上判断输出几个*后,输出固定个数的空格字符
急!一个Java题(在下图中的九个点上,空出中间的点...)
import javax.swing.JFrame ;
import javax.swing.JPanel ;
import java.awt.Graphics ;
import java.awt.BorderLayout ;
import java.awt.Color ;
import java.util.ArrayList ;
public class MobileSorter extends JFrame {
//上边距
public static final int TOP_SPA = 100 ;
//左边距
public static final int LEFT_SPA = 100 ;
public static void main(String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true) ;
MobileSorter ms = new MobileSorter() ;
ms.setVisible(true) ;
}
public MobileSorter() {
//设置窗体大小
this.setSize(400 ,400) ;
//new出组件
MyPanel p = new MyPanel() ;
//布置窗体
this.setLayout(new BorderLayout()) ;
this.add(p ,BorderLayout.CENTER) ;
//启动线程
Thread t = new Thread(p) ;
t.start() ;
}
}
class MyPanel extends JPanel implements Runnable {
//存储圆数据的数组
private ArrayList ca = new ArrayList(9);
/**
* 中心圆
*/
private Circle cCenter = null ;
public MyPanel() {
init() ;
}
public void paint(Graphics g) {
//画与5号位的斜连接线
for (int i = 0; i9; i++) {
if (i == 4) continue ;
Circle.drawLine(g ,(Circle)ca.get(4) ,(Circle) ca.get(i)) ;
}
//垂直和横线和竖线
g.setColor(Color.BLACK) ;
for (int i = 0; i9; i++)
for (int j = 0; j9; j++)
if (i != j i j)
if (j - i ==3 || (i + 1 == j j%3 != 0))
Circle.drawLine(g , (Circle) ca.get(i) ,(Circle) ca.get(j)) ;
/** 画圆 */
for (int i = 0; i9; i++)
((Circle) ca.get(i)).drawMe(g) ;
}
/**
* 初始化
*/
public void init() {
//创建圆
for (int i = 1; i10; i++)
this.ca.add(new Circle(i)) ;
//生成圆内的数
int[] n = new int[9] ;
for (int i = 0; in.length; ) {
int c ;
c = (int)(Math.random() * 8) + 1 ;
boolean isRepeat = false ;
for (int j = 0; ji; j++)
if (n[j] == c) {
isRepeat = true ;
break ;
}
if (isRepeat) continue ;
if (i == 4) i ++ ;
((Circle)this.ca.get(i)).setNum(c) ;
n[i] = c ;
i ++ ;
}
}
/**
* 线程
*/
public void run() {
int oPos = 0 ; //值为1的圆的标号
int sPos ; //值为1的圆的下一个圆的标号
int ePos ; //终端圆标号
int cPos = 0 ; //操作圆标号
cCenter = (Circle)this.ca.get(4) ; //中心圆
//找出圆内数字的1的圆
for (int i = 0; ithis.ca.size(); i++)
if (((Circle)this.ca.get(i)).getNum() == 1) {
oPos = i ;
break ;
}
sPos = Circle.getNextDeasil(oPos) ;
ePos = oPos ;
while (true) {
cPos = sPos ;
while (true) {
Circle c = (Circle)this.ca.get(cPos) ;
Circle n = (Circle)this.ca.get(Circle.getNextDeasil(cPos)) ;
checkSwap(c ,n) ;
cPos = Circle.getNextDeasil(cPos) ;
if(ePos == Circle.getNextDeasil(cPos)) {
ePos = cPos ;
break ;
}
}
if (ePos == Circle.getNextDeasil(sPos)) {
System.out.println ("OVER!") ;
break ;
}
}
}
/**
* 延迟
*/
private void animation() {
this.repaint() ;
try { Thread.sleep(1000) ;}catch (Exception ex) { }
}
/**
* 交换
*/
private void checkSwap(Circle c ,Circle n) {
int cNum = c.getNum() ;
int nNum = n.getNum() ;
if (cNum nNum) {
cCenter.setNum(n.getNum()) ;
n.setNum(0) ;
this.animation() ;
n.setNum(c.getNum()) ;
c.setNum(0) ;
this.animation() ;
c.setNum(cCenter.getNum()) ;
cCenter.setNum(0) ;
this.animation() ;
}
}
}
class Circle {
/**
* 各圆之间的间距
*/
public static final int CIR_SPA_BET = 60 ;
/**
* 圆的直径
*/
public static final int CIR_WD = 30 ;
/**
* 圆的标号 ,1-9
*/
private int pos ;
/**
* 圆的左上角x坐标
*/
private int x ;
/**
* 圆的左上角y坐标
*/
private int y ;
/**
* 圆内的数
*/
private int num ;
public Circle(int pos) {
this.pos = pos ;
this.x = MobileSorter.LEFT_SPA + (pos-1) % 3 * CIR_SPA_BET ;
this.y = MobileSorter.TOP_SPA + (pos-1) / 3 * CIR_SPA_BET ;
}
/**
* 画圆与圆中的数字
*/
public void drawMe(Graphics g) {
//圆
g.setColor(Color.BLACK) ;
g.fillOval(x ,y ,CIR_WD ,CIR_WD) ;
//数字
g.setColor(Color.WHITE) ;
if (num != 0)
g.drawString(String.valueOf(num)
,x + CIR_WD / 2 - 3 ,y + CIR_WD / 2 + 5) ;
else
g.drawString("空"
,x + CIR_WD / 2 - 3 ,y + CIR_WD / 2 + 5) ;
}
/**
* 画两个圆之间的连接线
*/
public static void drawLine(Graphics g ,Circle a , Circle b) {
g.drawLine(a.getX() + Circle.CIR_WD / 2
,a.getY() + Circle.CIR_WD / 2
,b.getX() + Circle.CIR_WD / 2
,b.getY()+ Circle.CIR_WD / 2) ;
}
public void setNum(int num) {
this.num = num ;
}
public int getX() {
return x ;
}
public int getY() {
return y ;
}
public int getPos() {
return pos ;
}
public int getNum() {
return num ;
}
public static int getNextDeasil(int pos) {
if (pos =0 pos =8 pos != 4) {
if (pos == 0)
return 1 ;
else if (pos == 1)
return 2 ;
else if (pos == 2)
return 5 ;
else if (pos == 3)
return 0 ;
else if (pos == 5)
return 8 ;
else if (pos == 6)
return 3 ;
else if (pos == 7)
return 6 ;
else if (pos == 8)
return 7 ;
}
return -1 ;
}
/**
* 根据顺时针方向返回下个圆的标号
*/
public int getNextDeasil() {
if (pos =0 pos =8 pos != 4) {
if (pos == 0)
return 1 ;
else if (pos == 1)
return 2 ;
else if (pos == 2)
return 5 ;
else if (pos == 3)
return 0 ;
else if (pos == 5)
return 8 ;
else if (pos == 6)
return 3 ;
else if (pos == 7)
return 6 ;
else if (pos == 8)
return 7 ;
}
return -1 ;
}
}
Java中的Tools.getInputWord是什么意思?
这是一个自定义的工具类 里面有一系列的静态方法
往往在项目开发过程中,有些共用的方法各个模块都有使用并且常用,但又不能直接随便放入到一个模块中,所以 一般是建立一个工具类,名字大多都叫tool tools Tool等,里面的空开方法都是静态,所以不需要实例化,只要用 类名.方法名/变量名 就可以了。
关于java空开和java开关按钮的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。