Up Previous Next

It becomes as follows:

import java.awt.*; 
import javax.swing.*; 
import java.rmi.*; 
import java.rmi.server.*; 

public class Client extends JFrame implements ClientInterface { 
  public Client(int columns, int rows) {
    this.setTitle("iceblox: client frame"); 
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
    this.setSize(columns * cellWidth + cellWidth / 2, (1 + rows) * cellHeight + cellHeight / 2); 
    getContentPane().add(new Surface(columns, rows), "Center"); 
    this.setVisible(true); 
  }  
  int cellWidth = 30, cellHeight = 30; 
  class Surface extends JPanel {
    int columns, rows; 
    Surface(int columns, int rows) { 
      this.columns = columns; 
      this.rows = rows; 
    }
    int fontSize = 10; // in pixels 
    Font digitsFont = new Font("Serif", Font.PLAIN, fontSize); 
    public void paintComponent(Graphics g) {
      super.paintComponent(g); 
      ((Graphics2D)g).setFont(digitsFont); 
      g.setColor(Color.black); 
      g.fillRect(0, 0, columns * cellWidth, rows * cellHeight); 
      g.setColor(Color.gray); 
      for (int i = 0; i <= rows; i++) 
        g.drawLine(0, i * cellHeight, columns * cellWidth, i * cellHeight); 
	for (int i = 0; i < columns; i++) { 
        g.drawLine(i * cellWidth, 0, i * cellWidth, rows * cellHeight); 
        g.drawRect(0, 0, cellWidth * columns, cellHeight * rows); 
        g.setColor(Color.gray);
      } 
      for (int j = 0; j < columns; j = j + 1) 
        for (int i = 0; i < rows; i++)
          g.drawString(i + ", " + j, j * cellWidth + 2, i * cellHeight + fontSize);	    
    }  
  } 
  ServerInterface server; 
  public void registerWith(ServerInterface server) throws RemoteException {
    this.server = server; 
    this.id = server.register(this);     
    System.out.println("I have registered, I have id: " + this.id); 
  } 
  int id = -1; 
  public static void main(String[] args) {
    try {
        ServerInterface far = (ServerInterface)Naming.lookup("rmi://" + args[0] +  ":" + args[1] + "/Dirac"); 
        int cols = 10, rows = 10; 
        Client here = new Client(cols, rows); 
        UnicastRemoteObject.exportObject(here); 
        here.registerWith(far); 
    } catch (Exception e) {
        System.out.println("Error in client..." + e); 
        e.printStackTrace();
    }
  } 
}

Up Previous Next