/** TabbedPaneDemo Constructor */ public TabbedPaneDemo(SwingSet2 swingset) { // Set the title for this demo, and an icon used to represent this // demo inside the SwingSet2 app. super(swingset, "TabbedPaneDemo", "toolbar/JTabbedPane.gif"); // create tab position controls JPanel tabControls = new JPanel(); tabControls.add(new JLabel(getString("TabbedPaneDemo.label"))); top = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.top"))); left = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.left"))); bottom = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.bottom"))); right = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.right"))); getDemoPanel().add(tabControls, BorderLayout.NORTH); group = new ButtonGroup(); group.add(top); group.add(bottom); group.add(left); group.add(right); top.setSelected(true); top.addActionListener(this); bottom.addActionListener(this); left.addActionListener(this); right.addActionListener(this); // create tab tabbedpane = new JTabbedPane(); getDemoPanel().add(tabbedpane, BorderLayout.CENTER); String name = getString("TabbedPaneDemo.laine"); JLabel pix = new JLabel(createImageIcon("tabbedpane/laine.jpg", name)); tabbedpane.add(name, pix); name = getString("TabbedPaneDemo.ewan"); pix = new JLabel(createImageIcon("tabbedpane/ewan.jpg", name)); tabbedpane.add(name, pix); name = getString("TabbedPaneDemo.hania"); pix = new JLabel(createImageIcon("tabbedpane/hania.jpg", name)); tabbedpane.add(name, pix); name = getString("TabbedPaneDemo.bounce"); spin = new HeadSpin(); tabbedpane.add(name, spin); tabbedpane .getModel() .addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { SingleSelectionModel model = (SingleSelectionModel) e.getSource(); if (model.getSelectedIndex() == tabbedpane.getTabCount() - 1) { spin.go(); } } }); }
void doExeCommand() { JViewport viewport = scrollPane.getViewport(); String strContent = new String(); PSlider slider; int i; File fp = new File(dataFile); RandomAccessFile access = null; Runtime program = Runtime.getRuntime(); String cmdTrigger = "trigger"; boolean delete = fp.delete(); try { fp.createNewFile(); } catch (IOException ie) { System.err.println("Couldn't create the new file " + ie); // System.exit(-1);; } try { access = new RandomAccessFile(fp, "rw"); } catch (IOException ie) { System.err.println("Error in accessing the file " + ie); // System.exit(-1);; } for (i = 0; i < COMPONENTS; i++) { slider = (PSlider) vSlider.elementAt(i); /* Modified on March 20th to satisfy advisors' new request */ if (slider.isString == true) strContent = strContent + slider.getRealStringValue() + " "; else strContent = strContent + slider.getValue() + " "; } // Get value of the radio button group if (firstBox.isSelected() == true) strContent = strContent + "1"; else strContent = strContent + "0"; try { access.writeBytes(strContent); access.close(); } catch (IOException ie) { System.err.println("Error in writing to file " + ie); // System.exit(-1);; } // Trigger the OpenGL program to update with new values try { Process pid = program.exec(cmdTrigger); } catch (IOException ie) { System.err.println("Couldn't run " + ie); // System.exit(-1);; } doSourceFileUpdate(); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == submit) { if (rb1.isSelected()) { JFrame frame = Application.getFrame(); if (typeCodes.isEmpty()) { JOptionPane.showMessageDialog( frame, "Please select at least one toponym type.", "Error", JOptionPane.ERROR_MESSAGE); } else { Application.getMainCitiesPanel(this, typeCodes, 0, 0.0); } } else if (rb2.isSelected()) { JFrame frame = Application.getFrame(); try { nCities = new Integer(nCitiesField.getText()); if (nCities <= 0) throw new NumberFormatException(); typeCodes = new ArrayList<String>(); Application.getMainCitiesPanel(this, typeCodes, nCities, 0.0); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( frame, "Please enter a positive integer number.", "Error", JOptionPane.ERROR_MESSAGE); } } else { JFrame frame = Application.getFrame(); try { Double dist = new Double(distField.getText()); if (dist <= 0) throw new NumberFormatException(); typeCodes = new ArrayList<String>(); Application.getMainCitiesPanel(this, typeCodes, 0, dist); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog( frame, "Please enter a positive number.", "Error", JOptionPane.ERROR_MESSAGE); } } } else { Application.getOptionPanel(this, countryName); } }
public MakeReservation() { new BorderLayout(); standardRoom.setMnemonic(KeyEvent.VK_K); standardRoom.setActionCommand("Standard Room"); standardRoom.setSelected(true); familyRoom.setMnemonic(KeyEvent.VK_F); familyRoom.setActionCommand("Family Room"); suiteRoom.setMnemonic(KeyEvent.VK_S); suiteRoom.setActionCommand("Suite"); // Add Booking Button ImageIcon bookRoomIcon = createImageIcon("images/book.png"); bookRoom = new JButton("Book Room", bookRoomIcon); bookRoom.setVerticalTextPosition(AbstractButton.BOTTOM); bookRoom.setHorizontalTextPosition(AbstractButton.CENTER); bookRoom.setMnemonic(KeyEvent.VK_M); bookRoom.addActionListener(this); bookRoom.setActionCommand("book"); // Group the radio buttons. group.add(standardRoom); group.add(familyRoom); group.add(suiteRoom); // Create the labels. nameLabel = new JLabel("Name: "); amountroomsLabel = new JLabel("How many rooms? "); checkoutdateLabel = new JLabel("Check-Out Date: "); checkindateLabel = new JLabel("Check-In Date: "); // Create the text fields and set them up. nameField = new JFormattedTextField(); nameField.setColumns(10); amountroomsField = new JFormattedTextField(new Integer(1)); amountroomsField.setValue(new Integer(1)); amountroomsField.setColumns(10); // java.util.Date dt_checkin = new java.util.Date(); LocalDate today = LocalDate.now(); // java.text.SimpleDateFormat sdf_checkin = new java.text.SimpleDateFormat("MM/dd/yyyy"); currentDate_checkin = today.toString(); checkindateField = new JFormattedTextField(currentDate_checkin); checkindateField.setColumns(10); // java.util.Date dt_checkout = new java.util.Date(); LocalDate tomorrow = today.plus(1, ChronoUnit.DAYS); // java.text.SimpleDateFormat sdf_checkout = new java.text.SimpleDateFormat("MM/dd/yyyy"); currentDate_checkout = tomorrow.toString(); checkoutdateField = new JFormattedTextField(currentDate_checkout); checkoutdateField.setColumns(10); // Tell accessibility tools about label/textfield pairs. nameLabel.setLabelFor(nameField); amountroomsLabel.setLabelFor(amountroomsField); checkoutdateLabel.setLabelFor(checkoutdateField); checkindateLabel.setLabelFor(checkindateField); // Lay out the labels in a panel. JPanel labelPane1 = new JPanel(new GridLayout(0, 1)); labelPane1.add(amountroomsLabel); JPanel labelPane3 = new JPanel(new GridLayout(0, 1)); labelPane3.add(checkindateLabel); JPanel labelPane2 = new JPanel(new GridLayout(0, 1)); labelPane2.add(checkoutdateLabel); JPanel labelPane4 = new JPanel(new GridLayout(0, 1)); labelPane4.add(nameLabel); // Layout the text fields in a panel. JPanel fieldPane1 = new JPanel(new GridLayout(0, 1)); fieldPane1.add(amountroomsField); JPanel fieldPane3 = new JPanel(new GridLayout(0, 1)); fieldPane3.add(checkindateField); JPanel fieldPane2 = new JPanel(new GridLayout(0, 1)); fieldPane2.add(checkoutdateField); JPanel fieldPane4 = new JPanel(new GridLayout(0, 1)); fieldPane4.add(nameField); // Put the radio buttons in a column in a panel. JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(standardRoom); radioPanel.add(familyRoom); radioPanel.add(suiteRoom); // Put the panels in this panel, labels on left, // text fields on right. setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); add(labelPane1, BorderLayout.LINE_START); add(fieldPane1, BorderLayout.LINE_END); add(labelPane3, BorderLayout.LINE_START); add(fieldPane3, BorderLayout.LINE_END); add(labelPane2, BorderLayout.LINE_START); add(fieldPane2, BorderLayout.LINE_END); add(labelPane4, BorderLayout.LINE_START); add(fieldPane4, BorderLayout.LINE_END); add(radioPanel, BorderLayout.LINE_END); add(bookRoom); }
public void bookRoom() { try { int code = 0; Connection con = DriverManager.getConnection( "jdbc:mysql://67.20.111.85:3306/jeehtove_caliking?relaxAutoCommit=false", "jeehtove_ck", "Z_^PBBZT+kcy"); Statement stmt_insert = con.createStatement(); Statement stmt_tableRange = con.createStatement(); Statement stmt_checkrooms = con.createStatement(); Statement stmt_checkrooms_2 = con.createStatement(); String insert = null; int flag = 0; String room_type; if (standardRoom.isSelected()) { room_type = "Standard"; code = 1; } else if (familyRoom.isSelected()) { room_type = "Family"; code = 2; } else { room_type = "Suite"; code = 3; } // Converting string from checkin and checkout dates so that they can access the correct table String currentDate_checkin_getText = checkindateField.getText(); String currentDate_checkin_rest = currentDate_checkin_getText.substring(5); String currentDate_checkin_replace = currentDate_checkin_rest.replace("-", "_"); String currentDate_checkin_year = currentDate_checkin.substring(0, 4); String currentDate_checkin_final = currentDate_checkin_year + "_" + currentDate_checkin_replace; String currentDate_checkout_getText = checkoutdateField.getText(); String currentDate_checkout_rest = currentDate_checkout_getText.substring(5); String currentDate_checkout_replace = currentDate_checkout_rest.replace("-", "_"); String currentDate_checkout_year = currentDate_checkout.substring(0, 4); String currentDate_checkout_final = currentDate_checkout_year + "_" + currentDate_checkout_replace; // MySQL Statement to select tables from schema that are in between checkin and checkout range String tableRange = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='jeehtove_caliking' AND TABLE_NAME BETWEEN 'rooms_" + currentDate_checkin_final + "' AND 'rooms_" + currentDate_checkout_final + "';"; ResultSet tb_Range = stmt_tableRange.executeQuery(tableRange); System.out.println(tableRange); List tb_range_list = new ArrayList(); while (tb_Range.next()) { String tb_range_date = tb_Range.getString("table_name"); tb_range_list.add(tb_range_date); // String current_table = tb_Range.getString("table_name"); // System.out.println(tb_range_list.add(tb_Range.getString("table_name"))); } stmt_tableRange.close(); for (int x = 0; x < tb_range_list.size(); x++) { String query_checkrooms = "SELECT * FROM " + tb_range_list.get(x) + " WHERE type = '" + code + "' AND booked = '0' LIMIT 1;"; // System.out.println(query_checkrooms); ResultSet checkrooms = stmt_checkrooms.executeQuery(query_checkrooms); while (checkrooms.next()) { String getroomnumber = checkrooms.getString("room"); insert = "INSERT INTO `reservations` VALUES ('" + getroomnumber + "', '" + checkindateField.getText() + "', '" + checkoutdateField.getText() + "', '" + room_type + "', '" + nameField.getText() + "');"; String bookroom = "UPDATE `" + tb_range_list.get(x) + "` SET booked = '1' WHERE room = '" + getroomnumber + "';"; // System.out.println(insert); int cr = stmt_checkrooms_2.executeUpdate(bookroom); flag = 1; System.out.println("Room Booked!"); } } if (flag == 1) { int rs = stmt_insert.executeUpdate(insert); } else { System.out.println("All " + room_type + " rooms are booked for the time requested."); } /*String query_checkrooms = "SELECT * FROM rooms_" + currentDate_checkin_final + " WHERE type = '" + code + "' AND booked = '0';"; System.out.println(query_checkrooms); Statement stmt_checkrooms = con.createStatement(); ResultSet checkrooms = stmt_checkrooms.executeQuery(query_checkrooms);*/ /*if (checkrooms.next()){ String getroomnumber = checkrooms.getString("room"); String insert = "INSERT INTO `reservations` VALUES ('" + getroomnumber + "', '" + checkindateField.getText() + "', '" + checkoutdateField.getText() + "', '" + room_type + "', '" + nameField.getText() + "');"; String bookroom = "UPDATE `rooms_" + currentDate_checkin_final + "` SET booked = '1' WHERE room = '" + getroomnumber + "';"; //System.out.println(insert); int rs=stmt_insert.executeUpdate(insert); int cr=stmt_checkrooms.executeUpdate(bookroom); con.commit(); System.out.println("Room Booked!"); }*/ // else System.out.println("All " + room_type + " rooms are booked for the time requested."); System.out.println("Complete."); } catch (Exception e) { System.out.println(e); } }
public void actionPerformed(ActionEvent a) { int code = 0; String roomtypeCompare_arr = null; String roomtypeCompare_dep = null; if ("book".equals(a.getActionCommand())) { try { Class.forName("com.mysql.jdbc.Driver"); // Database connection information. Please note that when porting the code, you must have // the jdbc Driver installed where the code is running. Connection con = DriverManager.getConnection( "jdbc:mysql://67.20.111.85:3306/jeehtove_caliking?relaxAutoCommit=true", "jeehtove_ck", "Z_^PBBZT+kcy"); // The SELECT query String query_arr = "SELECT * from reservations WHERE checkin BETWEEN '" + checkindateField.getText() + "' AND '" + checkoutdateField.getText() + "'"; String query_dep = "SELECT * from reservations WHERE checkout BETWEEN '" + checkindateField.getText() + "' AND '" + checkoutdateField.getText() + "'"; Statement stmt_arr = con.createStatement(); Statement stmt_dep = con.createStatement(); Statement stmt_insert = con.createStatement(); ResultSet result_arr = stmt_arr.executeQuery(query_arr); ResultSet result_dep = stmt_dep.executeQuery(query_dep); // Get room type from radio buttons String room_type; if (standardRoom.isSelected()) { room_type = "Standard"; code = 1; } else if (familyRoom.isSelected()) { room_type = "Family"; code = 2; } else { room_type = "Suite"; code = 3; } bookRoom(); // ResultSet rs=stmt.executeQuery("select * from emp"); /*if (!result_arr.next() && !result_dep.next()){ bookRoom(); //Query Prep for checking for open rooms /*String query_checkrooms = "SELECT * FROM makereservation_rooms WHERE type = '" + code + "' AND booked = '0';"; Statement stmt_checkrooms = con.createStatement(); ResultSet checkrooms = stmt_checkrooms.executeQuery(query_checkrooms); if (checkrooms.next()){ String getroomnumber = checkrooms.getString("room"); String insert = "INSERT INTO `reservations` VALUES ('" + getroomnumber + "', '" + checkindateField.getText() + "', '" + checkoutdateField.getText() + "', '" + room_type + "', '" + nameField.getText() + "');"; String bookroom = "UPDATE `makereservation_rooms` SET booked = '1' WHERE room = '" + getroomnumber + "';"; //System.out.println(insert); int rs=stmt_insert.executeUpdate(insert); int cr=stmt_checkrooms.executeUpdate(bookroom); con.commit(); System.out.println("Room Booked!"); } else System.out.println("All " + room_type + " rooms are booked for the time requested."); } else { if (result_arr.next()){ roomtypeCompare_arr = result_arr.getString("type"); System.out.println("(arrival) Does " + roomtypeCompare_arr + " equal " + room_type + "?"); if (roomtypeCompare_arr.equals(room_type)){ String checkindateDB_arr = result_arr.getString("checkin"); String checkoutdateDB_arr = result_arr.getString("checkout"); System.out.println("There is a room booked on " + checkindateDB_arr + " that checks out on " + checkoutdateDB_arr + ". Please select another date."); } else { System.out.println("Room Booked!"); } } } //System.out.println(query_dep); if (result_dep.next()){ roomtypeCompare_dep = result_dep.getString("type"); System.out.println("(departure) Does " + roomtypeCompare_dep + " equal " + room_type + "?"); if (roomtypeCompare_dep.equals(room_type)){ String checkindateDB_dep = result_dep.getString("checkin"); String checkoutdateDB_dep = result_dep.getString("checkout"); System.out.println("There is a room booked on " + checkindateDB_dep + " that checks out on " + checkoutdateDB_dep + ". Please select another date."); } else { System.out.println("Room Booked!"); } }*/ con.close(); } catch (Exception e) { System.out.println(e); } } }
void doSourceFileUpdate() { BufferedReader bufferIn = null; String str1 = new String(); String strContent = new String(); String sliderValue = new String(); String newLine = System.getProperty("line.separator"); StringBuffer strBuf = new StringBuffer(); RandomAccessFile access = null; String tempFile = "temp" + round + ".html"; File fp = new File(tempFile); boolean firstChoice = true; int posFound = 0; int i = 0; PSlider slider; // round += 1; // Read the original source file to input buffer try { bufferIn = new BufferedReader(new FileReader(exampleSource)); } catch (FileNotFoundException fe) { System.err.println("Example Source File not found " + fe); // System.exit(-1);; } // get the first line of the buffer. try { str1 = bufferIn.readLine(); } catch (IOException ie) { System.err.println("Error reading line from the buffer " + ie); // System.exit(-1);; } // Transfer the whole content of the input buffer to the string try { do strContent += str1 + newLine; while ((str1 = bufferIn.readLine()) != null); } catch (IOException ie) { System.err.println("Error readding content of the input buffer " + ie); // System.exit(-1);; } // do the replacement. // First having to update the code part that is active in this section before // doing variables updated. Look at the current active radiobutton to make decision if (secondBox.isSelected() == true) firstChoice = false; if (firstChoice == true) { String tempStr = new String(); strBuf = new StringBuffer(strContent); posFound = strContent.indexOf(textStr2); tempStr = "<font color=blue>/***********" + newLine + textStr2 + newLine + "***********/</font>"; strBuf.replace(posFound, posFound + textStr2.length(), tempStr); strContent = new String(strBuf); } else { String tempStr = new String(); strBuf = new StringBuffer(strContent); posFound = strContent.indexOf(textStr1); tempStr = "<font color=blue>/***********" + newLine + textStr1 + newLine + "***********/</font>"; strBuf.replace(posFound, posFound + textStr1.length(), tempStr); strContent = new String(strBuf); } for (i = COMPONENTS; i > 0; i--) { // get the current value of slider slider = (PSlider) vSlider.elementAt(i - 1); sliderValue = slider.getValue(); // construct the search string str1 = "JPOT$" + i; // get the position of the search string in the content string. while ((posFound = strContent.indexOf(str1)) != -1) { strBuf = new StringBuffer(strContent); strBuf.replace(posFound, posFound + str1.length(), sliderValue); strContent = new String(strBuf); } } boolean delete = fp.delete(); try { fp.createNewFile(); } catch (IOException ie) { System.err.println("Couldn't create the new file " + ie); // System.exit(-1);; } try { access = new RandomAccessFile(fp, "rw"); } catch (IOException ie) { System.err.println("Error in accessing the file " + ie); // System.exit(-1);; } try { access.writeBytes(strContent); access.close(); } catch (IOException ie) { System.err.println("Error in writing to file " + ie); // System.exit(-1);; } try { textPane.getDocument().putProperty(Document.StreamDescriptionProperty, null); URL url = new URL("file:" + tempFile + "#gohere"); textPane.setPage(url); delete = fp.delete(); } catch (IOException ie) { System.err.println("Can not get the example html file " + ie); // System.exit(-1);; } }