Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.ComponentOrientation;
- import java.awt.Container;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.sql.*;
- import javax.swing.ButtonGroup;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JRadioButton;
- import javax.swing.JScrollPane;
- import javax.swing.JTextField;
- import javax.swing.JTextPane;
- import javax.swing.text.StyledDocument;
- public class AClass extends JPanel implements ActionListener {
- public class Dbc {
- Connection con;
- Statement stm;
- ResultSet rs;
- ResultSet create;
- String[] name = new String[30];
- public String[] query(String q, int k){
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- System.out.println(e);
- System.exit(-1);
- }
- try{
- con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "user", "password");
- stm = con.createStatement();
- rs = stm.executeQuery(q);
- int i=0;
- while(rs.next()){
- name[i]=rs.getString(k);
- i++;
- }
- con.close();
- }catch(java.sql.SQLException e){
- System.err.println(e);
- System.exit(-1);
- }
- return name;
- }
- }
- private JTextField textField;
- private JButton search = new JButton("C\u0103utare");
- private JTextPane textPane = new JTextPane();
- private JScrollPane scrollPane = new JScrollPane();
- StyledDocument doc = textPane.getStyledDocument();
- Dbc d = new Dbc();
- JRadioButton rdModel = new JRadioButton("Caut\u0103 dup\u0103 model");
- JRadioButton rdBrand = new JRadioButton("Caut\u0103 dup\u0103 marc\u0103");
- private final ButtonGroup buttonGroup = new ButtonGroup();
- public AClass(){
- textPane.addKeyListener(new KeyAdapter() {
- public void keyPressed(KeyEvent e){
- char c = e.getKeyChar();
- if (c=='c'){
- textPane.setText("");
- textPane.setCaretPosition(0);
- }
- }
- });
- setBackground(Color.green);
- setLayout(null);
- textField = new JTextField();
- textField.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
- textField.setToolTipText("Scrie textul c\u0103utat");
- textField.setColumns(10);
- textField.setBounds(182, 5, 86, 20);
- textField.setLocation(750, 50);
- add(textField);
- search.setBounds(840, 47, 90, 25);
- search.addActionListener(this);
- add(search);
- textPane.setEditable(false);
- textPane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
- textPane.setBounds(200,100,800,300);
- textPane.setLocation(new Point(200, 300));
- scrollPane.setBounds(300, 150, 650, 550);
- scrollPane.setViewportView(textPane);
- add(scrollPane);
- rdBrand.setBackground(Color.GREEN);
- buttonGroup.add(rdBrand);
- rdBrand.setBounds(600, 40, 130, 23);
- add(rdBrand);
- rdModel.setBackground(Color.GREEN);
- buttonGroup.add(rdModel);
- rdModel.setBounds(600, 60, 130, 23);
- add(rdModel);
- }
- public void paintComponent(Graphics g){
- g.setColor(Color.black);
- }
- public void actionPerformed(ActionEvent e) {
- Object source = e.getSource();
- if(source==search){
- String[] b = new String[30];
- int id=0;
- String s = "";
- String r = "";
- if(rdBrand.isEnabled()){
- String a = textField.getText();
- if(a.equals("Something") || a.equals("something"))
- id=1;
- if(a.equals("Volkswagen") || a.equals("volkswagen"))
- id=2;
- if(a.equals("bmw") || a.equals("BMW"))
- id=3;
- for(int i=0;i<30;i++)
- b[i]=d.query("SELECT * FROM Mod WHERE ID ='"+id+"'", 2)[i];
- for(int k=0;k<30;k++)
- if(b[k]!=null){
- try{
- doc.insertString(0, b[k]+"\n", null);
- }catch(Exception e3) { System.out.println(e3); }
- }
- }
- if(rdModel.isEnabled()){
- String a = textField.getText();
- if(a.equals("Logan") || a.equals("logan"))
- s="Logan";
- if(a.equals("m3") || a.equals("M3") || a.equals("M 3"))
- s="M3";
- if(a.equals("3") || a.equals("Seria 3") || a.equals("seria 3") || a.equals("3 Series") || a.equals("3 series"))
- s="3 Series";
- if(a.equals("1310"))
- s="1310";
- if(a.equals("1300"))
- s="1300";
- if(a.equals("polo") || a.equals("Polo"))
- s="Polo";
- if(a.equals("golf") || a.equals("Golf"))
- s="Golf";
- if(a.equals("passat") || a.equals("Passat"))
- s="Passat";
- if(a.equals("X6") || a.equals("x6"))
- s="X6";
- r=d.query("SELECT Descriere from mod where model = '"+s+"'", 1)[0];
- try{
- doc.insertString(0, " "+r+"\n", null);
- }catch(Exception e2) { System.out.println(e2); }
- }
- }
- }
- public class Frame {
- public void main(String[] args) {
- new Frame();
- }
- public Frame(){
- JFrame gui = new JFrame();
- gui.setTitle("Title");
- gui.setSize(1000, 900);
- gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- AClass panel = new AClass();
- Container pane = gui.getContentPane();
- pane.add(panel);
- gui.setVisible(true);
- }
- }
- }
Add Comment
Please, Sign In to add comment