Guest User

Untitled

a guest
Jan 1st, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package foodchamfinal;
  7. import java.awt.Color;
  8. import java.sql.*;
  9. import java.sql.Connection;
  10. import java.sql.PreparedStatement;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13.  
  14. /**
  15. *
  16. * @author lenovo
  17. */
  18. public class trial extends javax.swing.JFrame implements Runnable {
  19.  
  20. /**
  21. * Creates new form trial
  22. */
  23. static Thread t;
  24. Connection con=null;
  25. PreparedStatement ps=null;
  26. ResultSet rs=null;
  27. public trial() {
  28. initComponents();
  29. }
  30. public void run(){
  31. try{
  32. System.out.println("in");
  33. Class.forName("com.mysql.jdbc.Driver");
  34. con=DriverManager.getConnection("jdbc:mysql://localhost:3306/userlogin","root","root");
  35. ps=con.prepareStatement("Select * from fc2 where table_no='Table1'");
  36. rs=ps.executeQuery();
  37. System.out.println("in");
  38.  
  39.  
  40. while(rs.next()){
  41. button.setBackground(Color.red);repaint();
  42. System.out.println("next in");
  43. try {
  44. text.setText(rs.getString("table_no")+" "+rs.getString("name")+" "+rs.getString("phone_no")+" "+rs.getString("Customize")+""+rs.getInt("quantity1")+""+rs.getString("normal1")+""+rs.getInt("quantity2")+""+rs.getString("normal2")+""+rs.getInt("quantity"));
  45. } catch (SQLException ex) {
  46. Logger.getLogger(trial.class.getName()).log(Level.SEVERE, null, ex);
  47. }
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. }catch(Exception e){
  55. System.out.println("Exception \n of \n foodcham project \n"+e);
  56. }
  57. }
  58.  
  59. /**
  60. * This method is called from within the constructor to initialize the form.
  61. * WARNING: Do NOT modify this code. The content of this method is always
  62. * regenerated by the Form Editor.
  63. */
  64. @SuppressWarnings("unchecked")
  65. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  66. private void initComponents() {
  67.  
  68. button = new javax.swing.JButton();
  69. jScrollPane2 = new javax.swing.JScrollPane();
  70. text = new javax.swing.JTextArea();
  71.  
  72. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  73.  
  74. button.setText("jButton1");
  75. button.addActionListener(new java.awt.event.ActionListener() {
  76. public void actionPerformed(java.awt.event.ActionEvent evt) {
  77. buttonActionPerformed(evt);
  78. }
  79. });
  80.  
  81. text.setColumns(20);
  82. text.setRows(5);
  83. jScrollPane2.setViewportView(text);
  84.  
  85. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  86. getContentPane().setLayout(layout);
  87. layout.setHorizontalGroup(
  88. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89. .addGroup(layout.createSequentialGroup()
  90. .addGap(85, 85, 85)
  91. .addComponent(button, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
  92. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  93. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
  94. .addContainerGap(73, Short.MAX_VALUE))
  95. );
  96. layout.setVerticalGroup(
  97. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98. .addGroup(layout.createSequentialGroup()
  99. .addGap(51, 51, 51)
  100. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  101. .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 348, javax.swing.GroupLayout.PREFERRED_SIZE)
  102. .addComponent(button, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
  103. .addContainerGap(90, Short.MAX_VALUE))
  104. );
  105.  
  106. pack();
  107. }// </editor-fold>
  108.  
  109. private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
  110.  
  111.  
  112. button.setBackground(Color.white);
  113.  
  114. }
  115.  
  116. /**
  117. * @param args the command line arguments
  118. */
  119. public static void main(String args[]) {
  120. /* Set the Nimbus look and feel */
  121. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  122. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  123. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  124. */
  125. try {
  126. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  127. if ("Nimbus".equals(info.getName())) {
  128. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  129. break;
  130. }
  131. }
  132. } catch (ClassNotFoundException ex) {
  133. java.util.logging.Logger.getLogger(trial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  134. } catch (InstantiationException ex) {
  135. java.util.logging.Logger.getLogger(trial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  136. } catch (IllegalAccessException ex) {
  137. java.util.logging.Logger.getLogger(trial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  138. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  139. java.util.logging.Logger.getLogger(trial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  140. }
  141. //</editor-fold>
  142.  
  143. /* Create and display the form */
  144.  
  145. java.awt.EventQueue.invokeLater(new Runnable() {
  146. public void run() {
  147. new trial().setVisible(true);
  148.  
  149. trial tt=new trial();
  150. t=new Thread(tt);
  151. t.start();
  152. }
  153. });
  154. }
  155.  
  156. // Variables declaration - do not modify
  157. private javax.swing.JButton button;
  158. private javax.swing.JScrollPane jScrollPane2;
  159. private javax.swing.JTextArea text;
  160. // End of variables declaration
  161. }
Add Comment
Please, Sign In to add comment