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

📄 graphconstructiondialog1.java

📁 P2P模拟器P2Psim的程序源码
💻 JAVA
字号:
package gui;

import javax.swing.JDialog;
import javax.swing.JSlider;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JCheckBox;
import javax.swing.JSpinner;
import java.util.Hashtable;
import javax.swing.SpinnerNumberModel;

//import graph.GraphEventManager;

public class GraphConstructionDialog1 extends JDialog
{

	public GraphConstructionDialog1()
	{
		initComponents();
	}

	protected void initComponents()
	{

		panelMain = new javax.swing.JPanel();
		
		labelNbLevels = new javax.swing.JLabel();
		labelWithProbability = new javax.swing.JLabel();
		
		//checkBoxWithProbability = new javax.swing.JCheckBox();		
		checkBoxWithProbability = new JCheckBox("Allow edges between nodes at");
		currentCheckBox = false;	
		checkBoxWithProbability.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) 
			{
				changeCheckBox();
			}
			});
		
		buttonConstruct = new javax.swing.JButton();
		buttonCancel = new javax.swing.JButton();

		sliderProbability = new JSlider(JSlider.HORIZONTAL,0,10,5);
		
		spinnerModelNbLevels =  new SpinnerNumberModel(2, 1, 10, 1); 
		spinnerNbLevels = new JSpinner(spinnerModelNbLevels);
	
		panelMain.setLayout(null);
		setSize(235,250);
		panelMain.setOpaque(false);
		setResizable(false);



		setTitle("Graph Construction Wizard Step 1");      
		setName("Graph Construction Wizard Step 1");
		addWindowListener(new java.awt.event.WindowAdapter() 
						  {
		   					   public void windowClosing(java.awt.event.WindowEvent evt) {
				   				   cancel();
		   					   }
			  			  });

		labelNbLevels.setText("Levels of hierarchy: ");   //#Changed
		labelNbLevels.setBounds(15,30,125,15);		
		panelMain.add(labelNbLevels);
		
		spinnerNbLevels.setBounds(145,28,40,20);
		panelMain.add(spinnerNbLevels);
		
		//checkBoxWithProbability.setText("Allow edges between nodes at");
		checkBoxWithProbability.setBounds(10,80,250,15);
		panelMain.add(checkBoxWithProbability);
		
		labelWithProbability.setText("different depth with probability: ");   //#Changed
		labelWithProbability.setBounds(30,98,200,15);
		panelMain.add(labelWithProbability);
		
		//textFieldProbability.setBounds(230,98,30,18);
		//panelMain.add(textFieldProbability);

		sliderProbability.setMajorTickSpacing(2);
		sliderProbability.setMinorTickSpacing(1);
		sliderProbability.setBounds(30, 120, 170, 40);
		
		Hashtable labelTable = new Hashtable();
		labelTable.put( new Integer( 0 ), new JLabel("0") );
		labelTable.put( new Integer( 10 ), new JLabel("1") );
		sliderProbability.setLabelTable( labelTable );
		sliderProbability.setPaintLabels(true);
		sliderProbability.setPaintTicks(true);

		panelMain.add(sliderProbability);
		
		buttonConstruct.setText("Construct");
		buttonConstruct.setBounds(10,180,100,30);
		buttonConstruct.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) 
			{
				construct();
			}
		});
		panelMain.add(buttonConstruct);
		
		buttonCancel.setText("Cancel");
		buttonCancel.setBounds(120,180,100,30);
		buttonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent evt) 
				{
					cancel();
				}
			});
		panelMain.add(buttonCancel);


        getContentPane().add(panelMain);
        setLocation(100,100);
}

  
	protected void cancel() 
	{
		setVisible(false);
		dispose();
	}
	
	protected void construct()
	{
		int properties[] = new int[2];
		properties[0] = ((SpinnerNumberModel)spinnerNbLevels.getModel()).getNumber().intValue();
		if (currentCheckBox)
		{
			System.out.println("With interconnecting edges");
			properties[1] = sliderProbability.getValue();
		}
		cancel();
		//System.out.println(properties[0] + " * " + properties[1]);
		
		GUIEventManager.getReference().eventConstructNetworkGraph(properties);
		
	}
	
	private void changeCheckBox()
	{
		if (currentCheckBox == false)
		{
			currentCheckBox = true;
		}
		else
		{
			currentCheckBox = false;
		}
	}
	
	private JPanel panelMain;
	
	private JLabel labelNbLevels;
	private JLabel labelWithProbability;
	
	private JCheckBox checkBoxWithProbability;				
	
	private JSlider sliderProbability;

	private SpinnerNumberModel spinnerModelNbLevels;
	private JSpinner spinnerNbLevels;
	
	private javax.swing.JButton buttonConstruct;
	private javax.swing.JButton buttonCancel;

	private boolean currentCheckBox;
}

⌨️ 快捷键说明

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