Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.util.*;
- import java.awt.EventQueue;
- import java.awt.List;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JTextField;
- import javax.swing.JRadioButton;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.LayoutStyle.ComponentPlacement;
- import javax.swing.JLabel;
- import javax.swing.JScrollBar;
- import javax.swing.JList;
- import javax.swing.JOptionPane;
- import javax.swing.JComboBox;
- import javax.swing.JCheckBox;
- import java.awt.Color;
- public class YRB extends JFrame {
- private JPanel contentPane;
- private JTextField textField;
- private JLabel lblName;
- private JTextField textField_1;
- private JComboBox comboBox;
- private String name;
- private int index;
- private String[] categorys = { "children", "cooking", "drama", "guide", "history", "horror", "humor", "mystery",
- "phil", "romance", "science", "travel" };
- private boolean proceed = false;
- private JTextField Book;
- private JLabel lblBook;
- private JComboBox comboBox_1;
- private JTextField textField_2;
- private JTextField textField_3;
- private YRB_DB yrbDb = new YRB_DB();
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- YRB frame = new YRB();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public YRB() {
- comboBox = new JComboBox();
- comboBox_1 = new JComboBox();
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 470, 434);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- textField = new JTextField();
- textField.setColumns(10);
- JButton btnEnter = new JButton("Submit");
- btnEnter.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String output;
- index = comboBox.getSelectedIndex();
- name = textField.getText();
- output = yrbDb.findCustomer(name);
- System.out.println("output str " + output);
- if (output != null) {
- textField_1.setText(output);
- comboBox.addItem("");
- for (int i = 0; i < categorys.length; i++) {
- comboBox.addItem(categorys[i]);
- }
- } else {
- textField_1.setText("Not found");
- }
- }
- });
- lblName = new JLabel("Cid");
- textField_1 = new JTextField();
- textField_1.setBackground(new Color(255, 255, 255));
- textField_1.setEditable(false);
- textField_1.setColumns(10);
- JList list = new JList();
- // String[] categorys = {"children",
- // "cooking","drama","guide","history"};
- // comboBox = new JComboBox(categorys);
- comboBox.setBackground(Color.WHITE);
- JLabel lblCategory = new JLabel("Category");
- Book = new JTextField();
- Book.setColumns(10);
- lblBook = new JLabel("Book");
- JButton bookButton = new JButton("Search");
- bookButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.out.println("testttttt");
- comboBox_1.removeAllItems();
- ArrayList<String> out = new ArrayList<String>();
- String cat = (String) comboBox.getSelectedItem();
- if (cat != "") {
- System.out.println("IN ");
- String title = Book.getText();
- out = yrbDb.find_book(cat, title);
- if (!out.isEmpty()) {
- for (String str : out) {
- comboBox_1.addItem(str);
- }
- } else {
- System.out.println("ERROEERFSDGF");
- comboBox_1.removeAllItems();
- JFrame frame = new JFrame("Sample frame");
- frame.setSize(400, 400);
- frame.setVisible(false);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JOptionPane.showMessageDialog(frame, "Book not found");
- }
- }
- else {
- System.out.println("ERROEERFSDGF");
- comboBox_1.removeAllItems();
- JFrame frame = new JFrame("Sample frame");
- frame.setSize(400, 400);
- frame.setVisible(false);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JOptionPane.showMessageDialog(frame, "Please select category");
- }
- }
- });
- comboBox_1.setBackground(Color.WHITE);
- JLabel lblNewLabel = new JLabel("Quantity");
- textField_2 = new JTextField();
- textField_2.setColumns(10);
- textField_3 = new JTextField();
- textField_3.setColumns(10);
- JLabel lblPrice = new JLabel("Price");
- JLabel lblResults = new JLabel("Results");
- JButton btnPurchase = new JButton("Purchase");
- bookButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- GroupLayout gl_contentPane = new GroupLayout(contentPane);
- gl_contentPane
- .setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane
- .createSequentialGroup()
- .addContainerGap().addGroup(gl_contentPane
- .createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPane
- .createSequentialGroup().addGroup(gl_contentPane
- .createParallelGroup(
- Alignment.LEADING)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
- .addGroup(gl_contentPane.createSequentialGroup()
- .addComponent(lblName).addGap(35))
- .addGroup(gl_contentPane.createSequentialGroup()
- .addComponent(lblBook).addGap(31)))
- .addComponent(lblResults).addComponent(lblCategory))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addComponent(Book)
- .addGroup(Alignment.TRAILING, gl_contentPane
- .createParallelGroup(Alignment.LEADING, false)
- .addGroup(gl_contentPane.createSequentialGroup().addGap(144)
- .addGroup(gl_contentPane
- .createParallelGroup(Alignment.LEADING)
- .addComponent(bookButton, Alignment.TRAILING)
- .addComponent(btnPurchase, Alignment.TRAILING)))
- .addComponent(btnEnter, Alignment.TRAILING))
- .addComponent(comboBox, Alignment.TRAILING, 0, 250, Short.MAX_VALUE)
- .addComponent(textField_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE,
- 361, Short.MAX_VALUE)
- .addComponent(textField, GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
- .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, 362,
- GroupLayout.PREFERRED_SIZE)))
- .addGroup(gl_contentPane.createSequentialGroup().addComponent(lblPrice)
- .addPreferredGap(ComponentPlacement.RELATED)
- .addComponent(textField_3, GroupLayout.PREFERRED_SIZE, 83,
- GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED).addComponent(lblNewLabel)
- .addPreferredGap(ComponentPlacement.RELATED).addComponent(textField_2,
- GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE)))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addComponent(list, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE).addGap(394)));
- gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane
- .createSequentialGroup().addGap(9)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblName).addComponent(
- textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnEnter)
- .addPreferredGap(ComponentPlacement.RELATED)
- .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addGroup(gl_contentPane.createSequentialGroup().addGap(17).addComponent(list,
- GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE))
- .addGroup(
- gl_contentPane.createParallelGroup(Alignment.BASELINE)
- .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 49,
- GroupLayout.PREFERRED_SIZE)
- .addComponent(lblCategory)))
- .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
- .addGroup(gl_contentPane.createSequentialGroup().addGap(12).addComponent(lblBook)
- .addPreferredGap(ComponentPlacement.RELATED).addComponent(bookButton))
- .addGroup(gl_contentPane.createSequentialGroup().addPreferredGap(ComponentPlacement.UNRELATED)
- .addComponent(Book, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE)))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblResults).addComponent(
- comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
- .addGap(18)
- .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
- .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE)
- .addComponent(lblNewLabel)
- .addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
- GroupLayout.PREFERRED_SIZE)
- .addComponent(lblPrice))
- .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnPurchase).addGap(27)));
- contentPane.setLayout(gl_contentPane);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement