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

📄 removerecordwindow.java

📁 myMileage是一个简单地系统
💻 JAVA
字号:
  import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.util.*;public class RemoveRecordWindow extends JFrame implements ActionListener , WindowListener {			private static RemoveRecordWindow instance = null;	private final String REMOVE = "Remove";	private final String CANCEL = "Cancel";		private static int rowIndex;	private String selection;		private JComboBox dateMenu = new JComboBox();		private Color bgcolor = Color.WHITE;		public static RemoveRecordWindow getInstance( int index ) {		if( instance == null ) instance = new RemoveRecordWindow( index );		return instance;	}		protected RemoveRecordWindow( int index ) { super(); this.makeGUI( index ); }		private void makeGUI( int index ) {		setTitle( "Remove A Record" );		Mileage m = Mileage.getInstance();		Point p = m.getLocation();		int x = (int)p.getX();		int y = (int)p.getY();		setLocation( x + 100 , y + 100 );		setBackground( bgcolor );		getContentPane().setLayout( new GridLayout( 3 , 1 ) );		setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE );		addWindowListener( this );		setSize( new Dimension( 260 , 120 ) );		addContent( index );		setVisible( true );	}		private void addContent( int index ) {		rowIndex = index;		JPanel labelPanel = new JPanel();		labelPanel.setBackground( bgcolor );		if( index != -1 ) {			labelPanel.add( new JLabel( "Are you sure you want to remove: " ) );		} else {			labelPanel.add( new JLabel( "Please select the entry to remove:" ) );		}		getContentPane().add( labelPanel );				Vector entries = Mileage.getInstance().getEntries();		JPanel datePanel = new JPanel();		if( index == -1 ) {			for( int i = 0; i < entries.size(); i++ ) {				dateMenu.addItem( ( (TableEntry)entries.get( i ) ).getVehicle() + 					": " + ( (TableEntry)entries.get( i ) ).getDate() );			}			dateMenu.setSelectedIndex( dateMenu.getItemCount() - 1 );			datePanel.add( dateMenu );		} else {			selection = (String)( (TableEntry)entries.get( index ) ).getVehicle() + 				": " + (String)( (TableEntry)entries.get( index ) ).getDate();;			datePanel.add( new JLabel( selection + "?" ) );		}				datePanel.setBackground( bgcolor );		getContentPane().add( datePanel );				JPanel buttonPanel = new JPanel();		buttonPanel.setLayout( new FlowLayout() );		buttonPanel.setBackground( bgcolor );		buttonPanel.add( makeButton( REMOVE ) );		buttonPanel.add( makeButton( CANCEL ) );		getContentPane().add( buttonPanel );	}			private JButton makeButton( String text ) {		JButton button = new JButton( text );		button.setActionCommand( text );		button.setToolTipText( text );		button.addActionListener( this );		return button;	}		public void actionPerformed( ActionEvent e ) {		String command = e.getActionCommand();				if( command.equals( REMOVE ) ) {			if( rowIndex == -1 ) {				String curSelection = (String)dateMenu.getSelectedItem();				Mileage.getInstance().removeRecord( curSelection );			} else {				Mileage.getInstance().removeRecord( selection );			}			windowClosing( null );		} else if( command.equals( CANCEL ) ) {			windowClosing( null );		}	}			public void windowClosing( WindowEvent e ) {		dispose();		instance = null;	}	public void windowActivated( WindowEvent e ) {}	public void windowClosed( WindowEvent e ) {}	public void windowDeactivated( WindowEvent e ) {}	public void windowDeiconified( WindowEvent e ) {}	public void windowIconified( WindowEvent e ) {}	public void windowOpened( WindowEvent e ) {}}

⌨️ 快捷键说明

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