Advertisement
Guest User

Untitled

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