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

📄 demobaseview.java

📁 手机无线网络纸牌游戏源代码。非常适合学习使用
💻 JAVA
字号:
// DemoBaseView.java
//
// Copyright (c) 2000-2001 Symbian Ltd. All rights reserved

package com.symbian.devnet.whist.awt;

import java.awt.*;
import java.awt.event.*;

/**
 * Class to control the view used to set up the Demo mode of operation.
 * @author Symbian Devnet
 */
public class DemoBaseView
{
	/** The <code>Panel</code> used to display the information on. */
	private Panel panel;
	/** The reference to the Whist game. */
	private Whist whistRef;
	/** An array of labels containing the names of the players. */
	private Label[] labels = new Label[4];
	/* The String representation of the IP address of the machine. */
	private String myUDPAddress;
	/** An array of empty labels used as padding for the layout. */
	private Label[] space = new Label[9];
	/**
	 * An array of labels containing the IP addresses of the machine(s) to be 
	 * used in the game. 
	 */
	private Label[] addresses = new Label[4];
	/** The confirmation button. */
	private Button OKbtn = new Button("OK");
	/** An array of the player names. */
	private String[] names = { "Player 1", "Player 2", "Player 3", "Player 4" };
	/** The port numbers used by the listeners when four emulators are running
	 * on one machine. */
	private String[] portNo = { ":1013", ":1010", ":1011", ":1012" };
			
	/**
	 * Constructor which sets the layout of the Panel
	 * Should only display if port this is listening on 1013.
	 * @param p the <code>Panel</code> used to display the information on
	 * @param w a reference to the Whist game.
	 */
	public DemoBaseView(Panel p, Whist w)
	{
		panel = p;
		whistRef = w;
		if (whistRef.port.equals("1013")) // portNo is only 1013 on the fourth emulator
		// running on one machine.
		{
			setUpSingleMachine();
		}					
		else if (whistRef.singleMachine) // the launch scrtipt did not specify that more 
		// than one machine is to be used and so it is assumed that four emulators on one
		// machine are required.  If this is not the fourth emulator to load, this code
		// is run which displays a message on the screen stating that four emulators are
		// not running and prevents the user from starting the demo.
		{
			panel.setLayout(new GridLayout(1,1));
			Label message = new Label("You need 4 emulators running");
			panel.add(message);
		}		
		else // (!whistRef.singleMachine) - assumes demo where emulators are on more 
		// than one machine.  This requires the addresses of all four machines to be
		// entered in the launch script for this option to be available.
		{
			setUpMultipleMachines();
		}
	}
	
	/** 
	 * Sets up the demo for four emulators running on one machine.
	 */
	private void setUpSingleMachine()
	{
		panel.setLayout(new GridLayout(9,2));
		labels[0] = new Label(names[0], Label.LEFT);
		labels[1] = new Label(names[1], Label.LEFT);
		labels[2] = new Label(names[2], Label.LEFT);
		labels[3] = new Label(names[3], Label.LEFT);	
		myUDPAddress = whistRef.myUDPAddress;		
					
		for (int i = 0; i < 4; i++)
		{
			addresses[i] = new Label(myUDPAddress);			
			panel.add(labels[i]);			
			panel.add(addresses[i]);
		}		
		for (int i = 0; i < 9; i++)
		{
			space[i] = new Label("");
			panel.add(space[i]);
		}

		panel.add(OKbtn);
		
		OKbtn.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{			
				String[] s = new String[4];
				for (int i = 0; i < 4; i++)
				{
					s[i] = ("udp://" + addresses[i].getText() + portNo[i]);
				}					
				whistRef.startGame(names, s);		
			}		
		});
	}
	
	/**
	 * Sets up the demo so that between 2 and 4 machines can be used for the demo.
	 * This allows variations on the following combinations: 1:1:1:1, 1:1:2, 1:3, 2:2.
	 */
	private void setUpMultipleMachines()
	{
		String[] adds = new String[4];
		myUDPAddress = whistRef.myUDPAddress;
		adds[0] = myUDPAddress;
		for (int i = 0; i < 3; i ++)
			adds[i+1] = whistRef.addresses[i];
		portNo = new String[4];	
		portNo[0] = whistRef.port;	
		
		portNo[1] = "1010";
		
		if (adds[2].equals(adds[1]))
		{
			portNo[2] = "1011";
			if (adds[3].equals(adds[2]))
				portNo[3] = "1012";
		}	
		else
		{
			portNo[2] = "1010";
			if ((adds[3].equals(adds[1])) || (adds[3].equals(adds[2])))
				portNo[3] = "1011";
			else 
				portNo[3] = "1010";
		} 	

		panel.setLayout(new GridLayout(9,2));
		labels[0] = new Label(names[0], Label.LEFT);
		labels[1] = new Label(names[1], Label.LEFT);
		labels[2] = new Label(names[2], Label.LEFT);
		labels[3] = new Label(names[3], Label.LEFT);			
					
		for (int i = 0; i < 4; i++)
		{
			addresses[i] = new Label(adds[i]);			
			panel.add(labels[i]);			
			panel.add(addresses[i]);
		}		
		for (int i = 0; i < 9; i++)
		{
			space[i] = new Label("");
			panel.add(space[i]);
		}

		panel.add(OKbtn);
		
		OKbtn.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent ae)
			{			
				String[] s = new String[4];
				for (int i = 0; i < 4; i++)
				{
					s[i] = ("udp://" + addresses[i].getText() + ":" + portNo[i]);
				}					
				whistRef.startGame(names, s);		
			}		
		});
	}
	
	/**
	 * Allows the Demo view to be redisplayed without creating a new one.  All old
	 * setup information is removed before displaying.
	 */
	public void demoBaseView()
	{
		panel.removeAll();	
						
		for (int i = 0; i < 4; i++)
		{			
			panel.add(labels[i]);			
			panel.add(addresses[i]);
		}		
		for (int i = 0; i < 9; i++)
		{
			space[i] = new Label("");
			panel.add(space[i]);
		}
		panel.add(OKbtn);
	}	
}

⌨️ 快捷键说明

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