www.pudn.com > P2P file system.rar > MainGUI.java


package server; 
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
 
class MainGUI extends JFrame 
{ 
	private Container container; 
	private JButton start,stop; 
 
	private P2PServer server; 
 
	public MainGUI() 
	{ 
		super("P2PServer"); 
		 
		container = getContentPane(); 
		container.setLayout(new FlowLayout()); 
 
		start = new JButton("Start server"); 
		stop = new JButton("Stop server"); 
		stop.setEnabled(false); 
		start.addActionListener( 
		new ActionListener(){ 
			public void actionPerformed( ActionEvent actionEvent) 
			{ 
				server = new P2PServer(); 
				start.setEnabled(false); 
				stop.setEnabled(true); 
			} 
		}); 
		 
		stop.addActionListener( 
		new ActionListener(){ 
			public void actionPerformed( ActionEvent actionEvent) 
			{ 
				server.close(); 
				start.setEnabled(true); 
				stop.setEnabled(false); 
			} 
		}); 
 
		container.add(start); 
		container.add(stop); 
 
		setLocation(200, 200); 
		setSize(160,120); 
		setVisible( true ); 
	} 
 
	public static void main(String[] args)  
	{ 
		MainGUI application = new MainGUI(); 
 
		application.setDefaultCloseOperation( 
			JFrame.EXIT_ON_CLOSE); 
	} 
}