Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » error when try to limit only one same jinternalframe visible(Java GUI)
error when try to limit only one same jinternalframe visible [message #1773286] Tue, 26 September 2017 05:21 Go to next message
cliff lawa is currently offline cliff lawaFriend
Messages: 2
Registered: September 2017
Junior Member
hi all,

i try to limit only one same jinternal frame show
this is my main code
public class frame3 extends JFrame {

	public JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					frame3 frame = new frame3();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	

	
	   
	
	/**
	 * Create the frame.
	 */
	public frame3() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);
		JDesktopPane desktop = new JDesktopPane();
		
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnDataKaryawan = new JMenu("Data Employee");
		menuBar.add(mnDataKaryawan);
		
		JMenuItem mntmData = new JMenuItem("Data");
		mntmData.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				data.getInstance().setVisible(true);
				data.getInstance().setBounds(1, 1, 450, 300);
				desktop.add(data.getInstance());
				}
		});
		
		
		
		
		mnDataKaryawan.add(mntmData);
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new CardLayout(0, 0));
		contentPane.add(desktop, "name_19268387084787");
		
	}
}

and jinternalframe

public class data extends JInternalFrame {
	private JTable table;
	static Connection connection = null;
	public void refreshTable(){
		PreparedStatement forquery = null;
		//kondisi PreparedStatement awal kosong(null)
		ResultSet resultr=null;
		//kondisi PreparedStatement awal kosong(null)
		try{
			String queryqry2="select * from karyawan";
			
			forquery = connection.prepareStatement(queryqry2);
			resultr=forquery.executeQuery();
			table.setModel(DbUtils.resultSetToTableModel(resultr));
			forquery.close();
			resultr.close();
		}
		catch(Exception error){
			error.printStackTrace();
		}
	}
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					
					data frame = new data();
					frame.setVisible(true);
					connection.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	private static data myInstance;
	public data() {
		connection=xamppkonek.konekdb();
		setResizable(true);
		setMaximizable(true);
		setIconifiable(true);
		setClosable(true);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 11, 414, 165);
		getContentPane().add(scrollPane);
		
		table = new JTable();
		scrollPane.setViewportView(table);
		refreshTable();
		
	}

	
	public static data getInstance() {
		 if (myInstance == null)
		 {
	            myInstance = new data();
	            }
			return myInstance;
	    }


}



when i try to click the data for second time error java.lang.IllegalArgumentException at desktop.add(data.getInstance());

please help me figure what wrong and how to fix it

i using eclipse oxygen with windowbuilder

Re: error when try to limit only one same jinternalframe visible [message #1773409 is a reply to message #1773286] Wed, 27 September 2017 14:32 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3056
Registered: July 2009
Senior Member
This is not a general programming help forum, your question has nothing specific to Eclipse. I suggest Stack Overflow for general programming questions.
Re: error when try to limit only one same jinternalframe visible [message #1773453 is a reply to message #1773409] Thu, 28 September 2017 04:25 Go to previous message
cliff lawa is currently offline cliff lawaFriend
Messages: 2
Registered: September 2017
Junior Member
Eric Rizzo wrote on Wed, 27 September 2017 14:32
This is not a general programming help forum, your question has nothing specific to Eclipse. I suggest Stack Overflow for general programming questions.


thank for direction i will try Stack Overflow.
Previous Topic:Setup error
Next Topic:Error Starting Eclipse
Goto Forum:
  


Current Time: Fri Dec 15 12:05:25 GMT 2017

Powered by FUDForum. Page generated in 0.02637 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software