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

📄 placeframe.java

📁 petrinets小程序
💻 JAVA
字号:
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;

import javax.swing.JFrame;


public class PlaceFrame extends JFrame{

	Panel Input, Buttons;
	static place actual;
	TextField NameField, TokenField, BreakField;	
	
	public PlaceFrame(place n){
		super("Places' characteristic");
	
		this.setLayout(new BorderLayout());
		
		this.add("North", new Label("Node"));
		
		actual = n;
		
		Input = new Panel();
		Input.setLayout(new GridLayout(0,2,2,2));
		NameField = new TextField(actual.getName(), 1);
		TokenField = new TextField(Integer.toString(actual.getTokens()), 1);
		BreakField = new TextField(1);
		Input.add(new Label("Name",Label.RIGHT));
		Input.add(NameField);
		Input.add(new Label("Token",Label.RIGHT));
		Input.add(TokenField);
		Input.add(new Label("Breakcondition",Label.RIGHT));
		Input.add(BreakField);
		this.add("Center", Input);
		
		Buttons = new Panel();
		Buttons.setLayout(new FlowLayout());
		Buttons.add(new Button("Ok"));
		Buttons.add(new Button("Cancel"));
		this.setVisible(true);
		this.add("South",Buttons);
		this.pack();
		this.resize(250, 180);
		this.move(this.location().x + 700, this.location().y + 500);
//		move(parent.location().x + 50, parent.location().y + 50);
		this.setResizable(false);
		
	}
	
	public static void main(String[] args) {
		
		PlaceFrame application = new PlaceFrame(actual);
		application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		
	}
	
	public void setPlace(place n){
		actual = n;
		NameField.setText(actual.getName());
		TokenField.setText(Integer.toString(actual.getTokens()));
		BreakField.setText("");
	}
	
	public boolean handleEvent(Event e){
		switch (e.id) {
		case Event.ACTION_EVENT:
			if (((String)e.arg).equals("Ok")) {
				actual.setName(NameField.getText());
				try {
					actual.setTokens(Integer.parseInt(TokenField.getText()));
					if (actual.getTokens() < 0)
						actual.setTokens(0);
				}
				catch (NumberFormatException n) {}
				this.hide();
				return true;
			}
			if (((String)e.arg).equals("Cancel")) {
				this.hide();
				return true;
			}
			return false;
			default:
				return super.handleEvent( e );
		}
	}

	/**
	 * 
	 */
	//private static final long serialVersionUID = 1L;
}

⌨️ 快捷键说明

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