⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queens_fc.java

📁 PRl教学程序 PRl教学程序 PRl教学程序
💻 JAVA
字号:
// by Neng-Fa Zhou
import java.awt.*;
import java.awt.event.*;
import bprolog.plc.Plc;
import java.applet.*;
import java.io.*;
import java.util.StringTokenizer;

public 
  class Queens_fc extends Applet {
    public int screenWidth=600;
    public int screenHeight=500;
    public Integer[] queens; 
    Color pieceColor = Color.red;
    public int n,w,h;
    
    public static void main(String args[]) {
      Frame f = new Frame("Queens_fc");
      f.addWindowListener(new WindowAdapter(){
	public void windowClosing(WindowEvent e){
	  System.exit(0);
	}});
      Queens_fc qf = new Queens_fc();
      qf.init();
      System.out.print("N=?");
      try {
	qf.n = Std_io.inputInt();
      }
      catch (IOException e){
	qf.n = 8;
      }
      qf.w = qf.screenWidth/(qf.n+2);
      qf.h = qf.screenHeight/(qf.n+2);
      qf.queens = new Integer[qf.n];
      f.add("Center",qf);
      //      qf.setSize(qf.screenWidth+10,qf.screenHeight+10);
      f.setSize(qf.screenWidth+10,qf.screenHeight+20);
      f.show();
      qf.run1();
      System.exit(0);
    }

    public void init(){
    }

    public void paint(Graphics g){
        drawBoard();
	if (queens!=null && queens[0]!=null) drawQueens(queens);
    }

    public void run1() {
      drawBoard();
      Plc.startPlc(new String []{});
      Plc goal = new Plc("queens", new Object[] {new Integer(n),this});
      Plc.exec("load('queens_fc')");
      goal.call();
      while (true);
    }

    public void drawBoard(){
      Graphics g = this.getGraphics();
      for (int i=0;i<n;i++)
	for (int j=0;j<n;j++){
	  g.drawRect((i+1)*w,(j+1)*h,w,h);
	}
    }

    public void drawQueens(Object[] pos){
      Graphics g = this.getGraphics();
      int col;
      for (int i=0;i<n;i++){
	col = ((Integer)pos[i]).intValue();
	queens[i] = (Integer)pos[i];
	g.setColor(pieceColor);
	g.fillOval((i+1)*w,col*h,w,h);
      }
    }
  }

class Std_io {
  public static int inputInt()
    throws IOException
  {
    DataInputStream data_std_in = new DataInputStream(System.in);
    String line = data_std_in.readLine();
    StringTokenizer st = new StringTokenizer(line);
    return Integer.parseInt(st.nextToken());
  }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -