Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.64 KB | None | 0 0
  1.  
  2. import java.awt.BorderLayout;
  3. import java.util.*;
  4. import java.awt.EventQueue;
  5. import java.awt.List;
  6.  
  7. import javax.swing.JFrame;
  8. import javax.swing.JPanel;
  9. import javax.swing.border.EmptyBorder;
  10. import javax.swing.JButton;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.ActionEvent;
  13. import javax.swing.JTextField;
  14. import javax.swing.JRadioButton;
  15. import javax.swing.DefaultComboBoxModel;
  16. import javax.swing.GroupLayout;
  17. import javax.swing.GroupLayout.Alignment;
  18. import javax.swing.LayoutStyle.ComponentPlacement;
  19. import javax.swing.JLabel;
  20. import javax.swing.JScrollBar;
  21. import javax.swing.JList;
  22. import javax.swing.JOptionPane;
  23. import javax.swing.JComboBox;
  24. import javax.swing.JCheckBox;
  25. import java.awt.Color;
  26.  
  27. public class YRB extends JFrame {
  28.  
  29. private JPanel contentPane;
  30. private JTextField textField;
  31. private JLabel lblName;
  32. private JTextField textField_1;
  33. private JComboBox comboBox;
  34. private String name;
  35. private int index;
  36. private String[] categorys = { "children", "cooking", "drama", "guide", "history", "horror", "humor", "mystery",
  37. "phil", "romance", "science", "travel" };
  38. private boolean proceed = false;
  39. private JTextField Book;
  40. private JLabel lblBook;
  41. private JComboBox comboBox_1;
  42. private JTextField textField_2;
  43. private JTextField textField_3;
  44. private YRB_DB yrbDb = new YRB_DB();
  45.  
  46. /**
  47. * Launch the application.
  48. */
  49. public static void main(String[] args) {
  50. EventQueue.invokeLater(new Runnable() {
  51. public void run() {
  52. try {
  53. YRB frame = new YRB();
  54. frame.setVisible(true);
  55. } catch (Exception e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. });
  60. }
  61.  
  62. /**
  63. * Create the frame.
  64. */
  65. public YRB() {
  66. comboBox = new JComboBox();
  67. comboBox_1 = new JComboBox();
  68. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  69. setBounds(100, 100, 470, 434);
  70. contentPane = new JPanel();
  71. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  72. setContentPane(contentPane);
  73.  
  74. textField = new JTextField();
  75. textField.setColumns(10);
  76.  
  77. JButton btnEnter = new JButton("Submit");
  78. btnEnter.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent e) {
  80. String output;
  81. index = comboBox.getSelectedIndex();
  82. name = textField.getText();
  83. output = yrbDb.findCustomer(name);
  84. System.out.println("output str " + output);
  85. if (output != null) {
  86.  
  87. textField_1.setText(output);
  88. comboBox.addItem("");
  89. for (int i = 0; i < categorys.length; i++) {
  90. comboBox.addItem(categorys[i]);
  91. }
  92. } else {
  93. textField_1.setText("Not found");
  94. }
  95. }
  96.  
  97. });
  98.  
  99. lblName = new JLabel("Cid");
  100.  
  101. textField_1 = new JTextField();
  102. textField_1.setBackground(new Color(255, 255, 255));
  103. textField_1.setEditable(false);
  104. textField_1.setColumns(10);
  105.  
  106. JList list = new JList();
  107. // String[] categorys = {"children",
  108. // "cooking","drama","guide","history"};
  109. // comboBox = new JComboBox(categorys);
  110.  
  111. comboBox.setBackground(Color.WHITE);
  112.  
  113. JLabel lblCategory = new JLabel("Category");
  114.  
  115. Book = new JTextField();
  116. Book.setColumns(10);
  117.  
  118. lblBook = new JLabel("Book");
  119.  
  120. JButton bookButton = new JButton("Search");
  121. bookButton.addActionListener(new ActionListener() {
  122. public void actionPerformed(ActionEvent e) {
  123. System.out.println("testttttt");
  124. comboBox_1.removeAllItems();
  125. ArrayList<String> out = new ArrayList<String>();
  126. String cat = (String) comboBox.getSelectedItem();
  127.  
  128. if (cat != "") {
  129. System.out.println("IN ");
  130. String title = Book.getText();
  131. out = yrbDb.find_book(cat, title);
  132. if (!out.isEmpty()) {
  133.  
  134. for (String str : out) {
  135. comboBox_1.addItem(str);
  136. }
  137. } else {
  138. System.out.println("ERROEERFSDGF");
  139. comboBox_1.removeAllItems();
  140. JFrame frame = new JFrame("Sample frame");
  141. frame.setSize(400, 400);
  142. frame.setVisible(false);
  143. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  144. JOptionPane.showMessageDialog(frame, "Book not found");
  145. }
  146. }
  147.  
  148. else {
  149. System.out.println("ERROEERFSDGF");
  150. comboBox_1.removeAllItems();
  151. JFrame frame = new JFrame("Sample frame");
  152. frame.setSize(400, 400);
  153. frame.setVisible(false);
  154. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  155. JOptionPane.showMessageDialog(frame, "Please select category");
  156.  
  157. }
  158.  
  159. }
  160. });
  161.  
  162. comboBox_1.setBackground(Color.WHITE);
  163.  
  164. JLabel lblNewLabel = new JLabel("Quantity");
  165.  
  166. textField_2 = new JTextField();
  167. textField_2.setColumns(10);
  168.  
  169. textField_3 = new JTextField();
  170. textField_3.setColumns(10);
  171.  
  172. JLabel lblPrice = new JLabel("Price");
  173.  
  174. JLabel lblResults = new JLabel("Results");
  175.  
  176. JButton btnPurchase = new JButton("Purchase");
  177. bookButton.addActionListener(new ActionListener() {
  178. public void actionPerformed(ActionEvent e) {
  179.  
  180.  
  181. }
  182. });
  183.  
  184.  
  185.  
  186.  
  187. GroupLayout gl_contentPane = new GroupLayout(contentPane);
  188. gl_contentPane
  189. .setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane
  190. .createSequentialGroup()
  191. .addContainerGap().addGroup(gl_contentPane
  192. .createParallelGroup(Alignment.TRAILING).addGroup(gl_contentPane
  193. .createSequentialGroup().addGroup(gl_contentPane
  194. .createParallelGroup(
  195. Alignment.LEADING)
  196. .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
  197. .addGroup(gl_contentPane.createSequentialGroup()
  198. .addComponent(lblName).addGap(35))
  199. .addGroup(gl_contentPane.createSequentialGroup()
  200. .addComponent(lblBook).addGap(31)))
  201. .addComponent(lblResults).addComponent(lblCategory))
  202. .addPreferredGap(ComponentPlacement.RELATED)
  203. .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
  204. .addComponent(Book)
  205. .addGroup(Alignment.TRAILING, gl_contentPane
  206. .createParallelGroup(Alignment.LEADING, false)
  207. .addGroup(gl_contentPane.createSequentialGroup().addGap(144)
  208. .addGroup(gl_contentPane
  209. .createParallelGroup(Alignment.LEADING)
  210. .addComponent(bookButton, Alignment.TRAILING)
  211. .addComponent(btnPurchase, Alignment.TRAILING)))
  212. .addComponent(btnEnter, Alignment.TRAILING))
  213. .addComponent(comboBox, Alignment.TRAILING, 0, 250, Short.MAX_VALUE)
  214. .addComponent(textField_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE,
  215. 361, Short.MAX_VALUE)
  216. .addComponent(textField, GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
  217. .addComponent(comboBox_1, GroupLayout.PREFERRED_SIZE, 362,
  218. GroupLayout.PREFERRED_SIZE)))
  219. .addGroup(gl_contentPane.createSequentialGroup().addComponent(lblPrice)
  220. .addPreferredGap(ComponentPlacement.RELATED)
  221. .addComponent(textField_3, GroupLayout.PREFERRED_SIZE, 83,
  222. GroupLayout.PREFERRED_SIZE)
  223. .addPreferredGap(ComponentPlacement.RELATED).addComponent(lblNewLabel)
  224. .addPreferredGap(ComponentPlacement.RELATED).addComponent(textField_2,
  225. GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE)))
  226. .addPreferredGap(ComponentPlacement.RELATED)
  227. .addComponent(list, GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE).addGap(394)));
  228. gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPane
  229. .createSequentialGroup().addGap(9)
  230. .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblName).addComponent(
  231. textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  232. .addPreferredGap(ComponentPlacement.RELATED).addComponent(btnEnter)
  233. .addPreferredGap(ComponentPlacement.RELATED)
  234. .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
  235. .addPreferredGap(ComponentPlacement.RELATED)
  236. .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
  237. .addGroup(gl_contentPane.createSequentialGroup().addGap(17).addComponent(list,
  238. GroupLayout.PREFERRED_SIZE, 1, GroupLayout.PREFERRED_SIZE))
  239. .addGroup(
  240. gl_contentPane.createParallelGroup(Alignment.BASELINE)
  241. .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 49,
  242. GroupLayout.PREFERRED_SIZE)
  243. .addComponent(lblCategory)))
  244. .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
  245. .addGroup(gl_contentPane.createSequentialGroup().addGap(12).addComponent(lblBook)
  246. .addPreferredGap(ComponentPlacement.RELATED).addComponent(bookButton))
  247. .addGroup(gl_contentPane.createSequentialGroup().addPreferredGap(ComponentPlacement.UNRELATED)
  248. .addComponent(Book, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
  249. GroupLayout.PREFERRED_SIZE)))
  250. .addPreferredGap(ComponentPlacement.RELATED)
  251. .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE).addComponent(lblResults).addComponent(
  252. comboBox_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  253. .addGap(18)
  254. .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
  255. .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
  256. GroupLayout.PREFERRED_SIZE)
  257. .addComponent(lblNewLabel)
  258. .addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
  259. GroupLayout.PREFERRED_SIZE)
  260. .addComponent(lblPrice))
  261. .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnPurchase).addGap(27)));
  262. contentPane.setLayout(gl_contentPane);
  263. }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement