Ejemplo n.º 1
0
  public hostelStatus() {
    setTitle("Hostel");
    connect();
    updateRecord();

    JFrame fr = new JFrame();
    Toolkit tkt = fr.getToolkit();
    Dimension frsize = tkt.getScreenSize();
    setBounds(frsize.width / 4, frsize.height / 12, frsize.width / 2, frsize.height / 8);
    setLayout(null);

    cn = getContentPane();
    cn.setBackground(new Color(190, 180, 170));

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    tl = new JLabel("Current Hostels Status");
    tl.setFont(new Font("Engravers MT", 1, 25));
    tl.setForeground(new Color(247, 251, 249));

    p1 = new JPanel();
    p1.setBounds(0, 0, 600, 50);
    p1.add(tl);
    p1.setBackground(new Color(31, 88, 166));
    cn.add(p1);

    b1 = new JButton("LOAD");
    b1.setMnemonic('L');
    b1.addActionListener(new dispListener());
    b1.setBounds(230, 320, 120, 30);

    b2 = new JButton("EXIT");
    b2.setMnemonic('X');
    b2.addActionListener(new exitListener());
    b2.setBounds(350, 320, 100, 30);

    cn.add(b1);
    cn.add(b2);

    table = new JTable(data, col);
    table.setFont(new Font("Serif", Font.BOLD, 16));
    table.setBackground(new Color(250, 250, 250));
    table.setEnabled(false);

    JScrollPane jsp = new JScrollPane(table);
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setBounds(5, 100, 590, 200);
    cn.add(jsp);

    screensize = Toolkit.getDefaultToolkit().getScreenSize();

    setSize(600, 400);
    setVisible(true);
    setVisible(true);
    setResizable(true);
    connect();
  }
Ejemplo n.º 2
0
  public static void main(String args[]) {

    JFrame frame = new JFrame("Drag Image");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final Clipboard clipboard = frame.getToolkit().getSystemClipboard();

    final JLabel label = new JLabel();
    //    Icon icon = new ImageIcon("/home/j2ee/Desktop/war.103.gif");
    //    label.setIcon(icon);
    label.setTransferHandler(new ImageSelection());

    MouseListener mouseListener =
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            JComponent comp = (JComponent) e.getSource();
            TransferHandler handler = comp.getTransferHandler();
            handler.exportAsDrag(comp, e, TransferHandler.COPY);
          }
        };
    label.addMouseListener(mouseListener);

    JScrollPane pane = new JScrollPane(label);
    contentPane.add(pane, BorderLayout.CENTER);

    JButton copy = new JButton("Copy");
    copy.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            // fire TransferHandler's built-in copy
            // action with a new actionEvent having
            // "label" as the source
            Action copyAction = TransferHandler.getCopyAction();
            copyAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) copyAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JButton clear = new JButton("Clear");
    clear.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            label.setIcon(null);
          }
        });

    JButton paste = new JButton("Paste");
    paste.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {
            // use TransferHandler's built-in
            // paste action
            Action pasteAction = TransferHandler.getPasteAction();
            pasteAction.actionPerformed(
                new ActionEvent(
                    label,
                    ActionEvent.ACTION_PERFORMED,
                    (String) pasteAction.getValue(Action.NAME),
                    EventQueue.getMostRecentEventTime(),
                    0));
          }
        });

    JPanel p = new JPanel();
    p.add(copy);
    p.add(clear);
    p.add(paste);
    contentPane.add(p, BorderLayout.SOUTH);

    frame.setSize(300, 300);
    frame.show();
  }