Example usage for java.awt Label Label

List of usage examples for java.awt Label Label

Introduction

In this page you can find the example usage for java.awt Label Label.

Prototype

public Label(String text) throws HeadlessException 

Source Link

Document

Constructs a new label with the specified string of text, left justified.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    // Create a test frame
    Frame frame = new Frame("Hello");
    frame.add(new Label("Minimize demo"));
    frame.pack();/*from   ww  w . j  a v a  2 s . c  o m*/

    // Show the frame
    frame.setVisible(true);

    // Sleep for 5 seconds, then minimize
    Thread.sleep(5000);
    frame.setState(Frame.ICONIFIED);
    frame.setVisible(false);
    // Sleep for 5 seconds, then restore
    Thread.sleep(5000);
    frame.setState(Frame.NORMAL);
    frame.setVisible(true);

    // Sleep for 5 seconds, then kill window
    Thread.sleep(5000);
    frame.setVisible(false);
    frame.dispose();

    // Terminate test
    System.exit(0);
}

From source file:Main.java

public static void main(String[] argv) {
    JFrame demo = new JFrame("GridBag demo, to center a component");
    JPanel parentPanel = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.CENTER;
    gridbag.setConstraints(parentPanel, constraints);
    parentPanel.setLayout(gridbag);/*from   w w  w .  ja  va 2s. c om*/
    Label centerLabel = new Label(" AAA...");
    parentPanel.add(centerLabel);
    demo.add(parentPanel);
    demo.setSize(500, 500);
    demo.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Frame f = new Frame("FlowLayout demo");
    f.setLayout(new FlowLayout());
    f.add(new Button("Red"));
    f.add(new Button("Blue"));
    f.add(new Button("White"));
    List list = new List();
    for (int i = 0; i < args.length; i++) {
        list.add(args[i]);//from www  .jav a 2s  . co  m
    }
    f.add(list);
    f.add(new Checkbox("Pick me", true));
    f.add(new Label("Enter name here:"));
    f.add(new TextField(20));
    f.pack();
    f.setVisible(true);
}

From source file:MouseDrag.java

public static void main(String[] av) {
    JFrame f = new JFrame("Mouse Dragger");
    Container cp = f.getContentPane();

    if (av.length < 1) {
        System.err.println("Usage: MouseDrag imagefile");
        System.exit(1);//w  w  w.  j  a v a 2 s  .  c  om
    }
    Image im = Toolkit.getDefaultToolkit().getImage(av[0]);

    // create a MouseDrag object
    MouseDrag j = new MouseDrag(im);

    cp.setLayout(new BorderLayout());
    cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java"));
    cp.add(BorderLayout.CENTER, j);
    cp.add(BorderLayout.SOUTH, status = new Label());
    status.setSize(f.getSize().width, status.getSize().height);
    f.pack();
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:MouseDragClip.java

public static void main(String[] av) {
    JFrame f = new JFrame("Mouse Dragger");
    Container cp = f.getContentPane();

    if (av.length < 1) {
        System.err.println("Usage: MouseDragClip imagefile");
        System.exit(1);/*from   w ww.  ja  v a  2s .c  om*/
    }
    Image im = Toolkit.getDefaultToolkit().getImage(av[0]);

    // create a MouseDragClip object
    MouseDragClip j = new MouseDragClip(im);

    cp.setLayout(new BorderLayout());
    cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java"));
    cp.add(BorderLayout.CENTER, j);
    cp.add(BorderLayout.SOUTH, status = new Label());
    status.setSize(f.getSize().width, status.getSize().height);
    f.pack();
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public Main() {
    super(BoxLayout.Y_AXIS);

    Box info = Box.createVerticalBox();
    info.add(new Label("Please wait 3 seconds"));
    final JButton continueButton = new JButton("Continue");
    info.add(continueButton);//from   www .  ja  v  a  2 s . c  o m

    JDialog d = new JDialog();
    d.setModalityType(ModalityType.APPLICATION_MODAL);
    d.setContentPane(info);
    d.pack();

    continueButton.addActionListener(e -> d.dispose());
    continueButton.setVisible(false);

    SwingWorker sw = new SwingWorker<Integer, Integer>() {
        protected Integer doInBackground() throws Exception {
            int i = 0;
            while (i++ < 30) {
                System.out.println(i);
                Thread.sleep(100);
            }
            return null;
        }

        @Override
        protected void done() {
            continueButton.setVisible(true);
        }

    };
    JButton button = new JButton("Click Me");
    button.addActionListener(e -> {
        sw.execute();
        d.setVisible(true);
    });
    add(button);
}

From source file:Main.java

public Main() {
    JPanel sliderPanel = new JPanel();
    sliderPanel.setLayout(new GridLayout(0, 1));
    for (int i = 0; i < slider.length; i++) {
        labels[i] = new Label(colorNames[i] + 255);
        sliderPanel.add(labels[i]);//from  w ww .  j a v a2 s  .co  m
        slider[i] = new JSlider(SwingConstants.HORIZONTAL, 0, 255, 255);
        slider[i].setMinorTickSpacing(10);
        slider[i].setMajorTickSpacing(50);
        slider[i].setPaintTicks(true);
        slider[i].setPaintLabels(true);
        sliderPanel.add(slider[i]);
    }
    lb = new Label("Colour");
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setModal(true);
    dialog.add(sliderPanel, BorderLayout.CENTER);
    dialog.add(lb, BorderLayout.SOUTH);
    dialog.pack();
    dialog.setLocation(200, 200);
    dialog.setTitle("Colour Dialog");
    dialog.setVisible(true);
}

From source file:PopupDemo.java

public PopupDemo() {
    MenuBar mb = new MenuBar();
    setMenuBar(mb);/* w  ww. ja v a  2s .  c  o  m*/
    Menu m = new Menu("file");
    mb.add(m);
    MenuItem item = new MenuItem("file-1");
    item.addActionListener(this);
    m.add(item);
    item = new MenuItem("file-2");
    m.add(item);

    setSize(100, 100);
    setLayout(new BorderLayout());

    Label l = new Label("label");
    addPopup(l, "label");
    add(l, "North");

    Panel p = new Panel();
    addPopup(p, "Panel");
    add(p, "Center");

    Button b = new Button("button");
    addPopup(b, "button");
    add(b, "South");
}

From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java

public ColorPreferences(Component parent) {
    _parent = parent;//from  w  w w.j a  va  2 s .  com
    setBorder(new EmptyBorder(10, 10, 10, 10));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel pickers = new JPanel();
    pickers.setLayout(new GridLayout(10, 2));

    pickers.add(new Label(Messages.t("preferences.color.scheme.current.label")));
    _comboBox = createSchemeCombobox();
    pickers.add(_comboBox);

    addColorChooser(pickers, "gates");
    addColorChooser(pickers, "background");
    addColorChooser(pickers, "bus-on");
    addColorChooser(pickers, "ground");
    addColorChooser(pickers, "off");
    addColorChooser(pickers, "wires-on");
    addColorChooser(pickers, "signal");
    addColorChooser(pickers, "grid");
    addColorChooser(pickers, "label");
    add(pickers);

    JPanel buttons = new JPanel();
    JButton button = new JButton(Messages.t("preferences.color.scheme.save.label"));
    buttons.add(button);
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });
    button = new JButton(Messages.t("preferences.color.scheme.new.label"));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), "");
            if (themeName != null) {
                while (ColorScheme.exists(themeName)) {
                    JOptionPane.showMessageDialog(_parent,
                            Messages.t("color.scheme.dialog.already.exists.error"), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    themeName = JOptionPane.showInputDialog(this, themeName);
                }
                ColorScheme.add(themeName);
                _comboBox.addItem(themeName);
                _comboBox.setSelectedItem(themeName);
            }
        }
    });
    buttons.add(button);
    add(buttons);
}

From source file:mineria.UI.java

public UI() {
    this.setLayout(new GridBagLayout());

    Label lblnodatos = new Label("NoDatos: ");
    Label label = new Label("BD: ");
    JTextField filename = new JTextField("/Users/eduardomartinez/Documents/mineria/representacion.txt");
    JTextField nodatos = new JTextField();
    nodatos.setText("500");

    JTextField funcion = new JTextField("6");
    JTextField individuos = new JTextField("200");
    JTextField enteros = new JTextField("1");
    JTextField decimales = new JTextField("40");
    JTextField variables = new JTextField("6");
    JTextField Pc = new JTextField("0.9");
    JTextField Pm = new JTextField("0.01");
    JTextField generaciones = new JTextField("100");
    JTextField minimiza = new JTextField("0");

    Label lblfuncion = new Label("funcion: ");
    Label lblindividuos = new Label("individuos: ");
    Label lblenteros = new Label("enteros: ");
    Label lbldecimales = new Label("decimales: ");
    Label lblvariables = new Label("variables: ");
    Label lblpc = new Label("Pc: ");
    Label lblpm = new Label("Pm: ");
    Label lblgeneraciones = new Label("generaciones: ");
    Label lblminimiza = new Label("[0 Min/1 Max] : ");

    /*// w w  w .j  a v  a2 s .  c  o m
    FN=funcion;
    N =individuos;
    E =bits_enteros;
    D =bits_decimales;
    V =variables;
    Pc=porcentaje_cruza;
    Pm=porcentaje_muta;
    G =generaciones;
    MM=minimiza;
    */

    JButton openBtn = new JButton("Open BD");
    JButton ejecutarEGA = new JButton("Ejecutar EGA");
    JTextField resultado = new JTextField();
    Label fitness = new Label("fitness: ");

    XYSeriesCollection datosSerie = new XYSeriesCollection();

    AGF agf = new AGF(2);
    EGA ega = new EGA();

    JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title
            "X", // x axis label
            "Y", // y axis label
            datosSerie, // data  ***-----PROBLEM------***
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // create and display a frame...
    ChartPanel panelChart = new ChartPanel(chart);

    //leer BD
    openBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            //datosSerie.removeAllSeries();
            if (filename.getText().length() > 0) {
                agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText()));

                createDataset(datosSerie, agf.data, "Datos");
                chart.fireChartChanged();
            } else {
                JFileChooser openFile = new JFileChooser();
                int rVal = openFile.showOpenDialog(null);
                if (rVal == JFileChooser.APPROVE_OPTION) {
                    filename.setText(openFile.getSelectedFile().getAbsolutePath());
                    agf.LeerDatos(filename.getText(), Integer.parseInt(nodatos.getText()));
                    //createDataset(datosSerie, agf.data, "Datos");
                    //chart.fireChartChanged();
                }
                if (rVal == JFileChooser.CANCEL_OPTION) {
                    filename.setText("");
                    //dir.setText("");
                }
            }
        }
    });

    ejecutarEGA.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            //datosSerie.removeAllSeries();
            if (datosSerie.getSeriesCount() > 1)
                datosSerie.removeSeries(1);

            int fn = Integer.parseInt(funcion.getText());
            int n = Integer.parseInt(individuos.getText());
            int e = Integer.parseInt(enteros.getText());
            int d = Integer.parseInt(decimales.getText());
            int v = Integer.parseInt(variables.getText());
            double pc = Double.parseDouble(Pc.getText());
            double pm = Double.parseDouble(Pm.getText());
            int g = Integer.parseInt(generaciones.getText());
            int mm = Integer.parseInt(minimiza.getText());

            ega.setParams(fn, n, e, d, v, pc, pm, g, mm);

            Resultado res = ega.ejecutarAlgoritmoGenetico(agf);

            resultado.setText(String.valueOf(res.getFitnessSemental()));

            res.creaArchivo();
            createDataset(datosSerie, res.getFenotipoSemental(), "Centros");

            Shape cross = ShapeUtilities.createDiagonalCross(5, 1);
            XYPlot xyPlot = (XYPlot) chart.getPlot();
            xyPlot.setDomainCrosshairVisible(true);
            xyPlot.setRangeCrosshairVisible(true);
            XYItemRenderer renderer = xyPlot.getRenderer();
            renderer.setSeriesShape(1, cross);
            renderer.setSeriesPaint(1, Color.blue);

            chart.fireChartChanged();

        }
    });
    //ejecutar AG

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblnodatos, gbc);

    gbc.gridx = 3;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(nodatos, gbc);

    gbc.gridx = 2;
    gbc.gridy = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(filename, gbc);

    gbc.gridx = 3;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(openBtn, gbc);

    gbc.gridx = 2;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(fitness, gbc);

    gbc.gridx = 3;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(resultado, gbc);

    gbc.gridx = 2;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(ejecutarEGA, gbc);

    //-----------------PARAMETROS
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblfuncion, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(funcion, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblindividuos, gbc);

    gbc.gridx = 1;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(individuos, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblenteros, gbc);

    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(enteros, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lbldecimales, gbc);

    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(decimales, gbc);

    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblvariables, gbc);

    gbc.gridx = 1;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(variables, gbc);

    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblpc, gbc);

    gbc.gridx = 1;
    gbc.gridy = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(Pc, gbc);

    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblpm, gbc);

    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(Pm, gbc);

    gbc.gridx = 0;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblgeneraciones, gbc);

    gbc.gridx = 1;
    gbc.gridy = 7;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(generaciones, gbc);

    gbc.gridx = 0;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(lblminimiza, gbc);

    gbc.gridx = 1;
    gbc.gridy = 8;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    this.add(minimiza, gbc);

    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 9;
    gbc.gridheight = 2;
    gbc.gridwidth = 4;
    this.add(panelChart, gbc);

    this.setTitle("File Chooser");

    this.pack();
}