Free
Flowing Switch Statement
public class FreeFlowingSwitchExample
{
public static void main(String[] args)
{
int i=0;
switch(i)
{
case 0:
System.out.println("i is 0");
case 1:
System.out.println("i is 1");
case 2:
System.out.println("i is 2");
default:
System.out.println("Free flowing switch
example!");
}
}
}
Get Horizontal Alignment of JLabel
import javax.swing.JApplet;
import javax.swing.JLabel;
public class GetHorizontalAlignmentExample
extends JApplet
{
public void init()
{
JLabel label1 = new JLabel("JLabel Get
Horizontal Alignment Example."); add(label1);
int alignment =
label1.getHorizontalAlignment();
switch(alignment)
{
case JLabel.LEFT:
label1.setText("Left");
break;
case JLabel.CENTER:
label1.setText("Center");
break;
case JLabel.RIGHT:
label1.setText("Right");
break;
case JLabel.LEADING:
label1.setText("Leading");
break;
case JLabel.TRAILING:
label1.setText("Trailing");
break;
}
}
}
Set Vertical Alignment of JLabel
import javax.swing.JApplet;
import javax.swing.JLabel;
public class JLabelVerticalAlignmentExample
extends JApplet
{
public void init()
{
JLabel label1 = new JLabel("JLabel Get
Horizontal Alignment Example.");add(label1);
int alignment = label1.getVerticalAlignment();
switch(alignment)
{
case JLabel.LEFT:
label1.setText("Left");
break;
case JLabel.CENTER:
label1.setText("Center");
break;
case JLabel.RIGHT:
label1.setText("Right");
break;
case JLabel.LEADING:
label1.setText("Leading");
break;
case JLabel.TRAILING:
label1.setText("Trailing");
break;
}
}
}
JTextField Horizontal Alignment
import java.awt.FlowLayout;
import javax.swing.JApplet;
import javax.swing.JTextField;
public class
JTextFieldHorizontalAlignmentExample extends JApplet
{
public void init()
{
this.getContentPane().setLayout(new
FlowLayout());
JTextField field = new
JTextField("JTextField Horizontal Alignment Example", 10);
int horizontalAlignment =
field.getHorizontalAlignment();
switch(horizontalAlignment)
{
case JTextField.LEFT:
field.setText("Left");
break;
case JTextField.RIGHT:
field.setText("Right");
break;
case JTextField.CENTER:
field.setText("Center");
break;
case JTextField.LEADING:
field.setText("Leading");
break;
case JTextField.TRAILING:
field.setText("Trailing");
break;
}
field.setHorizontalAlignment(JTextField.CENTER);
add(field);
}
}
No comments:
Post a Comment