A quick application to show a simple JLabel

Sunday, July 19th, 2009

//A quick application to show a simple JLabel.

import javax.swing.JFrame;
import javax.swing.JLabel;

public class SimpleJLabelExample {
  public static void main(String[] args) {
    JLabel label = new JLabel("A Very Simple Text Label");

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(label);
    frame.pack();
    frame.setVisible(true);
  }
}

           
       

Add image to Label and set ImageAlign to MiddleRight

Thursday, July 16th, 2009

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    private System.Windows.Forms.Label label1;

  public Form1() {
        InitializeComponent();
  }

    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.SuspendLayout();

        this.label1.Image = new Bitmap("winter.jpg");
        this.label1.ImageAlign = System.Drawing.ContentAlignment.TopRight;
        this.label1.Location = new System.Drawing.Point(20, 9);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(105, 77);
        this.label1.TabIndex = 0;
        this.label1.Text = "label1";

        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(299, 271);

        this.Controls.Add(this.label1);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "ImagesInCommonControls";
        this.Text = "ImagesInCommonControls";
        this.ResumeLayout(false);

    }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}

           
       

Using labels with loops

Tuesday, June 30th, 2009

SQL>
SQL> – Using labels with loops.
SQL> BEGIN
  2        <<outerloop>>
  3        FOR i IN 1..2 LOOP
  4             <<innerloop>>
  5             FOR j IN 1..4 LOOP
  6                  DBMS_OUTPUT.PUT_LINE(‘Outer Loop counter is ‘ || i ||
  7                       ‘ Inner Loop counter is ‘ || j);
  8             END LOOP innerloop;
  9        END LOOP outerloop;
 10  END;
 11  /
Outer Loop counter is 1 Inner Loop counter is 1
Outer Loop counter is 1 Inner Loop counter is 2
Outer Loop counter is 1 Inner Loop counter is 3
Outer Loop counter is 1 Inner Loop counter is 4
Outer Loop counter is 2 Inner Loop counter is 1
Outer Loop counter is 2 Inner Loop counter is 2
Outer Loop counter is 2 Inner Loop counter is 3
Outer Loop counter is 2 Inner Loop counter is 4

PL/SQL procedure successfully completed.

SQL>
SQL>
           
       

HTML label

Wednesday, June 24th, 2009

import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class HtmlLabel extends JFrame {
  public HtmlLabel() {
    super("HTML Buttons");
    setSize(400, 300);

    getContentPane().setLayout(new FlowLayout());

    String htmlText = "<html><p><font color=\"#800080\" "
        + "size=\"4\" face=\"Verdana\">JButton</font> </p>"
        + "<font size=\"2\"><em>" + "with HTML text</em></font></html>";
    JLabel btn = new JLabel(htmlText);
    getContentPane().add(btn);

    WindowListener wndCloser = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    };
    addWindowListener(wndCloser);
    setVisible(true);
  }

  public static void main(String args[]) {
    new HtmlLabel();
  }
}