Hi, Just wondering if anyone could help me with this, i'm using choice menus, in the PersonalDetails and the EventDetails parts, but when i run this they are both displayed in the PersonalDetails tab, this problem goes when i select the Event tab, can someone please help? import javax.swing.JTabbedPane; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JComponent; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.KeyEvent; import java.applet.*; import java.awt.*; import java.util.*; import java.awt.event.*; import java.applet.Applet; import javax.swing.*; import javax.swing.event.ChangeEvent; import java.io.*; import javax.swing.JScrollPane; //for scroll bars import java.sql.*; import java.awt.font.*;
public class TabbedDemo extends JApplet { public TabbedDemo() { JTabbedPane tabbedPane = new JTabbedPane(); ImageIcon icon = createImageIcon("middle.gif"); PersonalDetails pers = new PersonalDetails(); JComponent panel1 = pers.makePersonalDetails();
tabbedPane.addTab("Personal Details", icon, panel1, "Allows user to enter personal details"); tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
OtherDetails fam = new OtherDetails(); JComponent panel2 = fam.makeFOtherDetails("Panel #2"); tabbedPane.addTab("Family Tree", icon, panel2, "Gives a other details"); tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
EventDetails event = new EventDetails(); JComponent panel3 = event.makeEventDetails("Panel #3"); tabbedPane.addTab("Events", icon, panel3, "Allows user to enter event details"); tabbedPane.setMnemonicAt(2, KeyEvent.VK_3); tabbedPane.update(tabbedPane.getGraphics()); //Add the tabbed pane to this panel. this.getContentPane().add(tabbedPane);
//Uncomment the following line to use scrolling tabs. tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); int index = tabbedPane.getSelectedIndex(); } /** Returns an ImageIcon, or null if the path was invalid. */ protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = TabbedDemo.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("Family Tree"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. frame.getContentPane().add(new TabbedDemo(), BorderLayout.CENTER); //Display the window. frame.pack(); frame.setSize(600,350); frame.setVisible(true); } public void actionPerformed(ActionEvent event) { } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // passing in the parameters for the DB conenction conn = DriverManager.getConnection("jdbc racle:thin:@oracle.isg.computing.dcu.ie:1521 racle","username","password"); // creation and execution of the SQL query to check the username and password againt the DB Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT max(individid) FROM people"); int count = 0; if(rs.next()) count = rs.getInt("max(individid)"); count++; System.out.println(count); String query = "INSERT INTO people VALUES("+count+",'"+firstName+"','"+middleName+"','"+surname +"','"+maidenName+"','"+gender.substring(0,1)+"','"+photo+"','"+notes+"')"; System.out.println(query); stmt.executeQuery(query); stmt.executeQuery("commit");
} catch(SQLException e) // catch Exceptions realating to SQL commands { System.out.println("SQLException: " + e.getMessage()); while((e = e.getNextException()) != null) System.out.println(e.getMessage() + "<BR>"); } finally // only completes the following if after successful run of try block { //Clean up resources, close the connection. if(conn != null) { try { conn.close(); } catch (Exception ignored) { } } } } } import java.awt.event.*; import java.awt.Color; import java.awt.Choice; import javax.swing.*; import javax.swing.JScrollPane; //for scroll bars import javax.swing.text.JTextComponent; import java.sql.*; import java.applet.*; import java.awt.*; class EventDetails extends JPanel implements ActionListener { private JTextField firstNameField; private JTextField middleNameField; private JTextField surnameField; private JTextField maidenNameField; private Choice eventList; private Choice peopleList; private Choice dayList; private Choice monthList; private Choice yearList; private JButton submit; private JPanel inputPanel; protected JComponent makeEventDetails(String text) { inputPanel = new JPanel(); inputPanel.setBorder(BorderFactory.createTitledBorder("Events")); JLabel event = new JLabel("Choose Event"); event.setBounds( 100, 15, 80, 20 ); eventList = makeEventMenu("Choose"); eventList.setBounds( 190, 15, 150, 60 ); this.add(eventList); JLabel people = new JLabel("Choose person this relates to"); people.setBounds( 210, 215, 180, 20 ); peopleList = makePeopleMenu("Choose"); peopleList.setBounds( 410, 215, 150, 60 ); this.add(peopleList);
DateComboBox date = new DateComboBox(); date.setBounds( 10, 215, 80, 20 ); this.add(new DateComboBox());
submit = new JButton("Submit"); submit.setBounds( 190, 415, 80, 20 ); inputPanel.add(event); inputPanel.add(eventList); inputPanel.add(people); inputPanel.add(peopleList); inputPanel.add(date); inputPanel.add(submit); return inputPanel; } public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals("Submit")) inputData(); else System.out.println("fdsdafas"); } private Choice makeEventMenu(String inIntialChoice) { Choice menu = new Choice(); Connection conn = null; // try-catch needed when connecting to the database in case of connection disruption try { // Java DataBase Connection driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // passing in the parameters for the DB conenction conn = DriverManager.getConnection("jdbc racle:thin:@oracle.isg.computing.dcu.ie:1521 racle","username","password"); // creation and execution of the SQL query to check the username and password againt the DB Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM eventcode"); int count = 0; if(rs.next()) count = rs.getInt("count(*)"); String [] list = new String [count]; rs = stmt.executeQuery("SELECT Type FROM eventcode"); int i=0; while(rs.next() == true) { list[i] = rs.getString("Type"); i++; } for (i=0;i<count ;i++ ) { String theString =list[i]; menu.add(theString); } } catch(SQLException e) // catch Exceptions realating to SQL commands { System.out.println("SQLException: " + e.getMessage()); while((e = e.getNextException()) != null) System.out.println(e.getMessage()); }
return menu; } private Choice makePeopleMenu(String inIntialChoice) { Choice menu = new Choice(); Connection conn = null; // try-catch needed when connecting to the database in case of connection disruption try { // Java DataBase Connection driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // passing in the parameters for the DB conenction conn = DriverManager.getConnection("jdbc racle:thin:@oracle.isg.computing.dcu.ie:1521 racle","username","password"); // creation and execution of the SQL query to check the username and password againt the DB Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM people"); int count = 0; if(rs.next()) count = rs.getInt("count(*)"); String [] list = new String [count]; rs = stmt.executeQuery("SELECT fname, lname FROM people"); int i=0; while(rs.next() == true) { list[i] = rs.getString("fname"); list[i] += " " +rs.getString("lname"); i++; } for (i=0;i<count ;i++ ) { String theString =list[i]; menu.add(theString); }
Originally posted by Don Kiddick: Why do you add some or your components to 2 panels ? e.g. in EventDetails.makeEventDetails this.add( eventList ); ... inputPanel.add( eventList );
This is not a good thing ! D.
Yeah sorry, should be only once, messed about with it so much i've forgotten what i'm doing, still doesn't solve the problem though
I think the problem is that you are mixing awt & swing. Here is a document that examines the problems of mixing awt and Swing. This is particularly pertinent :
When a lightweight component overlaps a heavyweight component, the heavyweight component is always on top, regardless of the relative z-order of the two components.
To fix, I suggest you use JComboBox instead of Choice. D. [ March 01, 2004: Message edited by: Don Kiddick ]
Originally posted by Don Kiddick: I think the problem is that you are mixing awt & swing. Here is a document that examines the problems of mixing awt and Swing. This is particularly pertinent :
To fix, I suggest you use JComboBox instead of Choice. D. [ March 01, 2004: Message edited by: Don Kiddick ]
Yep, that fixed it. Thanks a lot
Post by:autobot
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
a bit of art, as a gift, the permaculture playing cards