Ejemplo n.º 1
0
  public Abschluss(String wahl, Sudoku s, Sudoku2 s2) {
    super("Sudoku-Abschluss");
    this.setSize(270, 135);
    this.setLocation(250, 300);
    this.setLayout(null);
    this.setAlwaysOnTop(true);
    this.setResizable(false);
    this.setUndecorated(true);
    if (s == null) this.setLocationRelativeTo(s2);
    else this.setLocationRelativeTo(s);

    su = s;
    su2 = s2;
    w = wahl;

    ImageIcon icon = new ImageIcon("files/minigames/Sudoku/beispiel2.jpg");
    icon.setImage(icon.getImage().getScaledInstance(290, 135, Image.SCALE_DEFAULT));

    lab = new JLabel(icon);
    lab.setSize(270, 135);
    lab.setLocation(0, 0);
    this.add(lab);

    text = new JLabel();
    text.setSize(250, 20);
    text.setLocation(10, 10);
    text.setForeground(Color.white);
    text.setHorizontalAlignment(0);
    lab.add(text);

    text2 = new JLabel();
    text2.setSize(270, 20);
    text2.setLocation(10, 30);
    text2.setForeground(Color.white);
    lab.add(text2);

    ok = new JButton("OK");
    ok.setSize(90, 30);
    ok.setLocation(80, 50);
    ok.setBorderPainted(false);
    ok.setBackground(Color.lightGray);
    ok.setForeground(Color.lightGray);
    ok.setOpaque(false);
    ok.setFont(new Font("Arial Black", 4, 20));
    ok.setContentAreaFilled(false);
    ok.setFocusPainted(false);
    ok.addActionListener(this);
    ok.addMouseListener(this);
    lab.add(ok);

    textWahl(wahl);

    this.setVisible(true);
  }
Ejemplo n.º 2
0
  Ccard() {
    OData.GenRnd(data, min, max, rnd_no); // 產生0~8亂數
    // 9個圖形物件
    for (i = 0; i <= 8; i++) {
      icon[i] = new ImageIcon("fig/p_" + i + ".jpg");
    }
    // 9個標籤亂數放圖
    k = 0;
    for (i = 0; i <= 2; i++) {
      for (j = 0; j <= 2; j++) {
        lbl[k] = new JLabel(icon[data[k]]);
        lbl[k].setBounds(10 + j * 160, 10 + i * 120, 160, 120);
        add(lbl[k]);
        lbl[k].addMouseListener(mouseObj); // 註冊傾聽者
        k++;
      }
    }

    lblCar.setSize(65, 43);
    add(lblCar);
    int width = 510, c_y = 375, c_time = 25;
    Thread ThCar = new Thread(new movePic(lblCar, width, c_y, c_time));
    ThCar.start();

    setTitle("3x3拼圖遊戲");
    setLayout(null);
    setBounds(100, 100, 510, 460);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
Ejemplo n.º 3
0
  private void processDrag(final MouseEvent e) {
    if (myDragCancelled) return;
    if (!isDraggingNow()) {
      if (myPressedPoint == null) return;
      if (isWithinDeadZone(e)) return;

      myDragPane = findLayeredPane(e);
      if (myDragPane == null) return;
      final BufferedImage image =
          new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
      paint(image.getGraphics());
      myDragButtonImage =
          new JLabel(new ImageIcon(image)) {

            public String toString() {
              return "Image for: " + StripeButton.this.toString();
            }
          };
      myDragPane.add(myDragButtonImage, JLayeredPane.POPUP_LAYER);
      myDragButtonImage.setSize(myDragButtonImage.getPreferredSize());
      setVisible(false);
      myPane.startDrag();
      myDragKeyEventDispatcher = new DragKeyEventDispatcher();
      KeyboardFocusManager.getCurrentKeyboardFocusManager()
          .addKeyEventDispatcher(myDragKeyEventDispatcher);
    }
    if (!isDraggingNow()) return;

    Point xy = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myDragPane);
    if (myPressedPoint != null) {
      xy.x -= myPressedPoint.x;
      xy.y -= myPressedPoint.y;
    }
    myDragButtonImage.setLocation(xy);

    SwingUtilities.convertPointToScreen(xy, myDragPane);

    final Stripe stripe =
        myPane.getStripeFor(new Rectangle(xy, myDragButtonImage.getSize()), (Stripe) getParent());
    if (stripe == null) {
      if (myLastStripe != null) {
        myLastStripe.resetDrop();
      }
    } else {
      if (myLastStripe != null && myLastStripe != stripe) {
        myLastStripe.resetDrop();
      }
      stripe.processDropButton(this, myDragButtonImage, xy);
    }

    myLastStripe = stripe;
  }
Ejemplo n.º 4
0
  public void init() {
    this.setPreferredSize(new Dimension(640, 480));
    pane = new JPanel();
    pane.setLayout(null);
    pane.setBackground(Color.CYAN);
    img = getImage(getCodeBase(), "zil_walk_front.gif");
    zil = new JLabel(new ImageIcon(img));

    zil.setSize(img.getWidth(this), img.getHeight(this));

    addKeyListener(this);
    pane.add(zil, 0, 0);
    add(pane, BorderLayout.CENTER);
    setFocusable(true);
  }
Ejemplo n.º 5
0
  LoginForm() {
    setDefaultLookAndFeelDecorated(true);
    f = new JFrame("LoginForm");
    f.setSize(750, 330);
    f.setLocation(200, 200);
    f.setResizable(false);
    JPanel p = new JPanel();
    f.getContentPane().add(p);
    p.setBackground(Color.white);
    icon = new ImageIcon("img.jpg");
    image = new JLabel(icon);
    image.setSize(100, 100);
    l2 = new JLabel("�");
    t1 = new JTextField(16);
    l3 = new JLabel("Password");
    jp1 = new JPasswordField(16);
    // img = getImage(getDocumentBase(), getParameter("img"));

    b1 = new JButton("Login");
    b2 = new JButton("Reset");
    b3 = new JButton("Cancel");
    l1 = new JLabel("       SANJEEVANI HOSPITAL");
    Font fk = new Font("Algerian", Font.BOLD, 40);
    l1.setFont(fk);
    l1.setForeground(Color.RED);
    l2 = new JLabel("UserName");
    l4 = new JLabel("�                                              ");

    p.add(l1);
    p.add(l4);
    p.add(l2);

    p.add(t1);

    p.add(l3);
    p.add(jp1);

    p.add(b1);
    p.add(b2);
    p.add(b3);
    p.add(image, BorderLayout.SOUTH);
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);

    f.setVisible(true);
  }
Ejemplo n.º 6
0
  private void mostrarGUI() {
    janela = new JFrame("Java Swing Examples");
    janela.setSize(400, 400);
    janela.setLayout(new GridLayout(3, 1));

    janela.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent windowEvent) {
            System.exit(0);
          }
        });

    statusLabel = new JLabel("", JLabel.CENTER);
    statusLabel.setSize(350, 100);

    controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());

    ImageIcon icon = criarImageIcon("/resources/home153.png", "Home");

    JButton okButton = new JButton("OK");
    // JButton homeButton = new JButton("Home", icon);

    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            statusLabel.setText("Clicou no Botao Ok.");
          }
        });

    /*
       homeButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
             statusLabel.setText("Clicou no Botao Home.");
          }
       });
    */

    controlPanel.add(okButton);
    // controlPanel.add(homeButton);

    janela.add(statusLabel);
    janela.add(controlPanel);
    janela.setVisible(true);
  }
Ejemplo n.º 7
0
  private void prepareGUI() {
    mainFrame = new JFrame("Java Swing Examples");
    mainFrame.setSize(400, 400);
    mainFrame.setLayout(new GridLayout(3, 1));
    mainFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent windowEvent) {
            System.exit(0);
          }
        });
    headerLabel = new JLabel("", JLabel.CENTER);
    statusLabel = new JLabel("", JLabel.CENTER);

    statusLabel.setSize(350, 100);

    controlPanel = new JPanel();
    controlPanel.setLayout(new FlowLayout());

    mainFrame.add(headerLabel);
    mainFrame.add(controlPanel);
    mainFrame.add(statusLabel);
    mainFrame.setVisible(true);
  }
Ejemplo n.º 8
0
  public Senso() {
    super("Senso");
    this.setSize(640, 480);
    this.setLocation(100, 100);
    this.getContentPane().setBackground(Color.black);
    this.setUndecorated(true);
    this.setBackground(Color.white);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setResizable(false);
    this.setLayout(null);
    this.setAlwaysOnTop(true);

    klicks = new JLabel();
    klicks.setSize(150, 25);
    klicks.setLocation(20, 300);
    klicks.setFont(new Font("Impact", 5, 25));
    klicks.setForeground(Color.lightGray);
    this.add(klicks);

    start = new JLabel();
    start.setSize(350, 50);
    start.setLocation(350, 200);
    start.setFont(new Font("Impact", 5, 50));
    start.setForeground(Color.lightGray);
    this.add(start);

    lblVerloren = new JLabel();
    lblVerloren.setSize(350, 30);
    lblVerloren.setLocation(200, 215);
    lblVerloren.setFont(new Font("Impact", 5, 30));
    lblVerloren.setForeground(Color.lightGray);
    this.add(lblVerloren);

    neustart = new JLabel("Neustart");
    neustart.setSize(100, 30);
    neustart.setLocation(20, 200);
    neustart.setFont(new Font("Impact", 5, 25));
    neustart.setForeground(Color.darkGray);
    neustart.addMouseListener(this);
    this.add(neustart);

    beenden = new JLabel("Beenden");
    beenden.setSize(100, 30);
    beenden.setLocation(20, 390);
    beenden.setFont(new Font("Impact", 5, 25));
    beenden.setForeground(Color.gray);
    beenden.addMouseListener(this);
    this.add(beenden);

    us = new JLabel("Senso");
    us.setSize(150, 35);
    us.setLocation(10, 30);
    us.setFont(new Font("Impact", 1, 35));
    us.setForeground(Color.white);
    this.add(us);

    punkte = new JLabel("Score: " + String.valueOf(points));
    punkte.setSize(200, 20);
    punkte.setLocation(400, 400);
    punkte.setFont(new Font("Impact", 0, 20));
    punkte.setForeground(Color.white);
    this.add(punkte);

    rot = new JLabel(new ImageIcon("files/Minigames/Senso/red_0.png"));
    rot.setSize(216, 207);
    rot.setLocation(150, 25);
    rot.setBackground(Color.darkGray);
    rot.addMouseListener(this);
    this.add(rot);

    gruen = new JLabel(new ImageIcon("files/Minigames/Senso/green_0.png"));
    gruen.setSize(216, 207);
    gruen.setLocation(366, 25);
    gruen.setBackground(Color.darkGray);
    gruen.addMouseListener(this);
    this.add(gruen);

    gelb = new JLabel(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
    gelb.setSize(216, 207);
    gelb.setLocation(366, 232);
    gelb.setBackground(Color.darkGray);
    gelb.addMouseListener(this);
    this.add(gelb);

    blau = new JLabel(new ImageIcon("files/Minigames/Senso/blue_0.png"));
    blau.setSize(216, 207);
    blau.setLocation(150, 232);
    blau.setBackground(Color.darkGray);
    blau.addMouseListener(this);
    this.add(blau);

    this.addMouseListener(this);

    // spiel = new Thread(this);
    zufall = new Random();

    läuft = false;

    zahl = zufall.nextInt(4);
    // this.setVisible(true);
    soundR = new File("files/Minigames/Senso/rot.wav");
    soundG = new File("files/Minigames/Senso/gruen.wav");
    soundB = new File("files/Minigames/Senso/blau.wav");
    soundY = new File("files/Minigames/Senso/gelb.wav");
    soundF = new File("files/Minigames/Senso/falsch.wav");
  }
Ejemplo n.º 9
0
  void setupGUI() {
    taDictionary = new TextArea();
    taDictionary.setLocation(0, 0);
    taDictionary.setSize(106, 567);
    taDictionary.setBackground(new Color(-1));
    taDictionary.setText("");
    taDictionary.setRows(5);
    taDictionary.setColumns(1);
    getContentPane().add(taDictionary);

    tfSourc = new TextField();
    tfSourc.setLocation(224, 90);
    tfSourc.setSize(266, 25);
    tfSourc.setBackground(new Color(-1));
    tfSourc.setText("");
    tfSourc.setColumns(10);
    getContentPane().add(tfSourc);

    lblSourc = new Label();
    lblSourc.setLocation(106, 90);
    lblSourc.setSize(119, 25);
    lblSourc.setText("Source Word:");
    getContentPane().add(lblSourc);
    /*
    lblDestinatio = new Label();
    lblDestinatio.setLocation(106,97);
    lblDestinatio.setSize(119,25);
    lblDestinatio.setText("Destination Wor");
    getContentPane().add(lblDestinatio);
       */

    lblDestinatio = new Label();
    lblDestinatio.setLocation(106, 120);
    lblDestinatio.setSize(119, 25);
    lblDestinatio.setText("Destination Word:");
    getContentPane().add(lblDestinatio);

    lblWordSize = new Label();
    lblWordSize.setLocation(106, 27); // 106,120
    lblWordSize.setSize(119, 25);
    lblWordSize.setText("Word Size:");
    getContentPane().add(lblWordSize);

    tfWordSize = new TextField();
    tfWordSize.setLocation(224, 27); // 224,120
    tfWordSize.setSize(263, 25);
    tfWordSize.setBackground(new Color(-1));
    tfWordSize.setText("5");
    tfWordSize.setColumns(10);
    getContentPane().add(tfWordSize);

    tfSourc_6 = new TextField();
    tfSourc_6.setLocation(226, 120);
    tfSourc_6.setSize(263, 25);
    tfSourc_6.setBackground(new Color(-1));
    tfSourc_6.setText("");
    tfSourc_6.setColumns(10);
    getContentPane().add(tfSourc_6);

    lblFileNam = new Label();
    lblFileNam.setLocation(104, 0);
    lblFileNam.setSize(119, 25);
    lblFileNam.setText("FilePath:");
    getContentPane().add(lblFileNam);

    tfFilePat = new TextField();
    tfFilePat.setLocation(224, 0);
    tfFilePat.setSize(266, 25);
    tfFilePat.setBackground(new Color(-1));

    // OS Detection
    if (System.getProperty("os.name").startsWith("Windows")) {
      // includes: Windows 2000,  Windows 95, Windows 98, Windows NT, Windows Vista, Windows XP
      tfFilePat.setText("c:\\ics340\\words.txt");
      System.out.println("Detected Windows: " + System.getProperty("os.name"));
    } else {
      tfFilePat.setText("/Users/jasonedstrom/ics340/d1.txt");
      System.out.println("Detected Mac OS X: " + System.getProperty("os.name"));
    }

    tfFilePat.setColumns(10);
    getContentPane().add(tfFilePat);

    btLoadTextFiel = new JButton();
    btLoadTextFiel.setLocation(108, 50); // 108,27
    btLoadTextFiel.setSize(198, 32);
    btLoadTextFiel.setText("Load Words from Text Field");
    getContentPane().add(btLoadTextFiel);

    btLoadFil = new JButton();
    btLoadFil.setLocation(306, 50); // 306,27
    btLoadFil.setSize(183, 32);
    btLoadFil.setText("Load Words from File");
    getContentPane().add(btLoadFil);

    btFindPat = new JButton();
    btFindPat.setLocation(106, 160);
    btFindPat.setSize(384, 38);
    btFindPat.setText("Find Path");
    getContentPane().add(btFindPat);

    lblDictCoun = new JLabel();
    lblDictCoun.setLocation(108, 513);
    lblDictCoun.setSize(300, 27);
    lblDictCoun.setForeground(new Color(-65536));
    lblDictCoun.setText("Words in Dictionary = 0 words");
    getContentPane().add(lblDictCoun);

    lblIndexing1 = new JLabel();
    lblIndexing1.setLocation(107, 454);
    lblIndexing1.setSize(130, 27);
    lblIndexing1.setForeground(new Color(-16777216));
    lblIndexing1.setText("");
    getContentPane().add(lblIndexing1);

    lblFindPat = new JLabel();
    lblFindPat.setLocation(108, 540);
    lblFindPat.setSize(250, 27);
    lblFindPat.setForeground(new Color(-14646771));
    lblFindPat.setText("Time to find Path: 0 milliseconds");
    getContentPane().add(lblFindPat);

    lblCos = new JLabel();
    lblCos.setLocation(360, 540);
    lblCos.setSize(175, 27);
    lblCos.setForeground(new Color(-16777216));
    lblCos.setText("Cost of Path: 0.0");
    getContentPane().add(lblCos);

    lblProgres = new JLabel();
    lblProgres.setLocation(108, 484);
    lblProgres.setSize(371, 26);
    lblProgres.setForeground(new Color(-14646771));
    lblProgres.setText("Time to Build Graph: 0 milliseconds");
    getContentPane().add(lblProgres);

    testpanel = new JPanel();
    testpanel.setLocation(106, 200);
    testpanel.setSize(350, 200);
    testpanel.setForeground(new Color(-14646771));
    // testpanel.setText("Test Location");
    getContentPane().add(testpanel);

    btClear = new JButton();
    btClear.setLocation(355, 513);
    btClear.setSize(125, 25);
    btClear.setText("Clear Results");
    getContentPane().add(btClear);

    // add actionlisteners to buttons
    btFindPat.addActionListener(this);
    btLoadTextFiel.addActionListener(this);
    btLoadFil.addActionListener(this);
    btClear.addActionListener(this);

    setTitle("WordLadderGUI");
    setSize(500, 600);
    setVisible(true);
    setResizable(false);
  }
Ejemplo n.º 10
0
  @Override
  public void actionPerformed(ActionEvent actionEvent) {
    Object obj = actionEvent.getSource();

    if (obj == btFindPat) {

      testpanel.removeAll();
      validate();
      repaint();
      if (taDictionary.getText().isEmpty()) {
        JOptionPane.showMessageDialog(
            frame, "Please load words so they appear in Text Area before Finding Path. ");

      } else if ((tfSourc.getText().isEmpty()) || (tfSourc_6.getText().isEmpty())) {
        JOptionPane.showMessageDialog(
            frame, "Please enter Source and Destination words before Finding Path. ");
      } else if (testpanel.getComponents().length != 0) {
        JOptionPane.showMessageDialog(frame, "Please clear results before continuing.");
      } else {
        wordLadder.findPath(
            tfSourc.getText(), tfSourc_6.getText(), Integer.parseInt(tfWordSize.getText()));
        lblFindPat.setText(
            "Time to find Path: " + String.valueOf(wordLadder.getTimeForPath()) + " milliseconds");
        lblCos.setText("Cost of Path: " + String.valueOf(wordLadder.g.getCost()));
        results = wordLadder.getResults();
        Collections.reverse(results);
        int x = 10;
        int y = 20;

        for (String s : results) {
          x += 20;
          y += 20;
          JLabel _lbl = new JLabel(s);
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);

          if (results.indexOf(s) == 0) {
            _lbl.setForeground(new Color(-14646771));
          } else if (results.indexOf(s) == (results.size() - 1)) {
            _lbl.setForeground(new Color(-8254711));
          } else {
            _lbl.setForeground(new Color(-16777216));
          }
          testpanel.add(_lbl);
          testpanel.repaint();
        }
        if (wordLadder.g.getCost() == 0) {
          // if (wordLadder.g.getGraphError() != null){
          JLabel _lbl = new JLabel(wordLadder.g.getGraphError());
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);
          testpanel.add(_lbl);
          testpanel.repaint();
          // }

        }
      }
      /*if (taDictionary.getText().isEmpty()){
      wordLadder = new WordLadder(tfFilePat.getText(), tfSourc.getText(), tfSourc_6.getText());
       }else if (!taDictionary.getText().isEmpty()){
          ArrayList<String> taList = new ArrayList<String>();
          StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
          while (stringTokenizer.hasMoreTokens()) {
              String token = stringTokenizer.nextToken();
              taList.add(token);
          }
        */
      // }
    }

    if (obj == btLoadFil) {
      clearData();
      // wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      // String size = tfWordSize.getText();
      // int intSize = Integer.parseInt(size);
      // WordLadderGUI.showMessage("Loading words of" + tfWordSize.getText() + " characters from
      // file: " + tfFilePat.getText(), Color.GREEN, Color.GREEN);
      lblIndexing1.setText("Indexing...");
      System.out.println(
          "Loading words of "
              + tfWordSize.getText()
              + " characters from file: "
              + tfFilePat.getText());
      wordLadder = new WordLadder(tfFilePat.getText(), Integer.parseInt(tfWordSize.getText()));
      // wordLadder.
      guiDictionary = new WordCollection(wordLadder.getWordList());
      WordLadderGUI.showMessage(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText(),
          Color.GREEN,
          Color.GREEN);
      System.out.println(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText());
      taDictionary.setText(guiDictionary.toString());
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }

    if (obj == btLoadTextFiel) {
      wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      String taDump = taDictionary.getText();
      System.out.println("Loading Words from Text Area");
      lblIndexing1.setText("Indexing...");
      ArrayList<String> taList = new ArrayList<String>();
      StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
      while (stringTokenizer.hasMoreTokens()) {
        String token = stringTokenizer.nextToken();
        taList.add(token);
      }
      guiDictionary = new WordCollection();
      guiDictionary.setWords(taList);
      wordLadder = new WordLadder(taList);
      WordLadderGUI.showMessage(
          "Loading " + wordLadder.getWordList().size() + " words from Text Field",
          Color.GREEN,
          Color.GREEN);
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }
    if (obj == btClear) {
      testpanel.removeAll();
      testpanel.validate();
      testpanel.repaint();
      wordLadder = null;
      lblCos.setText("Cost of Path: 0.0");
      lblCos.repaint();
      lblDictCoun.setText("Words in Dictionary = 0 words");
      lblFindPat.setText("Time to find Path: 0 milliseconds");
      tfSourc.setText("");
      tfSourc_6.setText("");
      taDictionary.setText("");
      results = null;
      lblProgres.setText("Time to Build Graph: 0 milliseconds");
    }
  }
Ejemplo n.º 11
0
  public General_Info() {

    pic.setIcon(userPic);
    String url = "jdbc:odbc:lib";

    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      connection = DriverManager.getConnection(url);
    } catch (ClassNotFoundException cnfex) {
      System.err.println("Failed to load driver");
      cnfex.printStackTrace();
      System.exit(1);
    } catch (SQLException sqlex) {
      System.err.println("unable to connect");
      sqlex.printStackTrace();
    }

    // validation for telephone
    tel_text.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (!((Character.isDigit(c)
                || (c == KeyEvent.VK_BACK_SPACE)
                || (c == KeyEvent.VK_DELETE)))) {
              getToolkit().beep();
              e.consume();
            }
          }
        });

    // validation for fax
    fax_text.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (!((Character.isDigit(c)
                || (c == KeyEvent.VK_BACK_SPACE)
                || (c == KeyEvent.VK_DELETE)))) {
              getToolkit().beep();
              e.consume();
            }
          }
        });

    patron_text.setText("P-");
    patron_text.addFocusListener(
        new MyActionListener() {
          public void focusLost(FocusEvent e) {

            try {
              Statement statement = connection.createStatement();

              String query2 =
                  "SELECT * FROM patronmaster " + "WHERE id = '" + patron_text.getText() + "'";

              ResultSet rs2 = statement.executeQuery(query2);
              int cnt = 0;
              while (rs2.next()) {
                cnt++;
              }
              if (cnt != 0) {

                try {
                  userPic = new ImageIcon(patron_text.getText() + ".gif");
                  pic.setIcon(userPic);
                } catch (Exception ex) {
                  ex.printStackTrace();
                  pic.setIcon(userPic);
                }

                String query1 =
                    "SELECT * FROM patronmaster " + "WHERE id = '" + patron_text.getText() + "'";

                ResultSet rs1 = statement.executeQuery(query1);
                try {
                  rs1.next();

                  int confirm =
                      JOptionPane.showConfirmDialog(
                          null,
                          "This record Exists, would you like to update it?",
                          "CONFIRM",
                          JOptionPane.YES_NO_OPTION);
                  if (confirm == JOptionPane.NO_OPTION) {
                    patron_text.setEditable(false);
                    name_text.setEditable(false);
                    passport_text.setEditable(false);
                    expiry_date_text.setEditable(false);
                    reg_by_text.setEditable(false);
                    reg_date_text.setEditable(false);
                    textArea.setEditable(false);
                    tel_text.setEditable(false);
                    fax_text.setEditable(false);
                    email_text.setEditable(false);
                  } else {

                  }
                  name_text.setText(rs1.getString(2));
                  passport_text.setText(rs1.getString(3));
                  expiry_date_text.setText(rs1.getString(6));
                  reg_by_text.setText(rs1.getString(7));
                  reg_date_text.setText(rs1.getString(8));
                  textArea.setText(rs1.getString(9));
                  tel_text.setText(rs1.getString(10));
                  fax_text.setText(rs1.getString(11));
                  email_text.setText(rs1.getString(12));
                  status_combo.setSelectedItem(rs1.getString(4));
                  salute_combo.setSelectedItem(rs1.getString(5));
                  group_combo.setSelectedItem(rs1.getString(13));

                  statement.close();

                } catch (SQLException sqlex) {
                  pic.setIcon(userPic);
                }
              }
            } catch (SQLException sqlex) {
              pic.setIcon(userPic);
            }
          }
        });

    scroll.add(address);
    scroll.add(scrollPane);

    text.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridy = 0;
    gbc.gridx = 0;
    text.add(tel, gbc);
    gbc.gridy = 1;
    text.add(fax, gbc);
    gbc.gridy = 2;
    text.add(email, gbc);
    gbc.gridy = 0;
    gbc.gridx = 2;
    text.add(tel_text, gbc);
    gbc.gridy = 1;
    text.add(fax_text, gbc);
    gbc.gridy = 2;
    text.add(email_text, gbc);

    pic.setSize(50, 50);
    pane1.add(scroll, BorderLayout.CENTER);
    pane1.add(pic, BorderLayout.EAST);
    pane1.add(text, BorderLayout.WEST);

    add(pane1);
  }
Ejemplo n.º 12
0
  // private void createComponent(){
  //
  // }
  public void init() {

    fLogin = new JFrame("Login");
    Container fc = fLogin.getContentPane();

    JPanel jpBtn = new JPanel(); // add jpanel, contains 2 buttons
    JButton btnLogin = new JButton("Login");
    JButton btnQuit = new JButton("Quit");
    btnLogin.setActionCommand("Login");
    btnQuit.setActionCommand("Quit");

    jpBtn.add(btnLogin);
    jpBtn.add(btnQuit);

    JPanel jpTextField = new JPanel(); // add jpanel contains 2label and 2 textfield

    jlName = new JLabel("User Name:");
    jlPwd = new JLabel("Password :"******"User001", 15);
    jfPwd = new JTextField("user001", 15);
    jlTips = new JLabel("");
    jlTips.setForeground(Color.red);
    jlTips.setSize(15, 15);
    jpTextField.add(jlName);
    jpTextField.add(jfName);
    jpTextField.add(jlPwd);
    jpTextField.add(jfPwd);
    jpTextField.add(jlTips);
    // f

    String output[] = {"GUI", "Konsole"};
    try {
      jfIp = new JTextField(InetAddress.getLocalHost().getHostAddress().toString());
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      jfIp.setText("127.0.0.1");
    }
    jfIp.setSize(20, 10);
    Jclass = new JComboBox(output);
    Jclass.setSize(150, 80);
    JPanel jcontainer = new JPanel();

    JLabel jblServer = new JLabel("Server Ip");
    JPanel jServer = new JPanel();
    jServer.add(jblServer);
    jServer.add(jfIp);

    jcontainer.setLayout(new BorderLayout());
    jcontainer.add(jpTextField, "Center");

    jcontainer.add(Jclass, "South");
    jcontainer.add(jServer, "North");

    // fc.add(jpTextField,"North");
    fc.add(jpBtn, "South");
    fc.add(jcontainer, "Center");
    // Event for window closing
    fLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    /*fLogin.addWindowListener(new WindowAdapter(){

    	public void windowClosing(WindowEvent e){
    	//	fLogin.dispose();
    		System.exit(0);
    	}

    });*/

    btnQuit.addActionListener(this);
    btnLogin.addActionListener(this);
    fLogin.setSize(300, 200);
    setFrameCenter(fLogin, false);
    fLogin.setVisible(true);
  }