Back to feed
Renewal·서른의 생활코딩

Ex5) Java AWT

NS
normalstory
cover image
import java.awt.*;
import java.awt.event.*;

public class LabelTest {
private Frame frame;
// Label object declaration
private Label first, second, third;
// constructor
public LabelTest() {
// 프레임 object creation
frame = new Frame( "Label" );
// 세개의 Label object creation
first = new Label( );
second = new Label( "나이" );
third = new Label( "address", Label.RIGHT ); //Label.정렬방식 initialization!!!

// 윈도우 종료 event
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
});
// 각 Label의 배경색을 지정
first.setBackground( Color.red );
second.setBackground( Color.blue );
third.setBackground( Color.green );
//변경!!!
//method를 call해서 Label object에 값을 세팅하거나,
//Label이 지니고 있는 값을 얻어옴
first.setText( "이름" ); 
second.setAlignment( Label.CENTER );
System.out.println( "Text Of lb2 : " + second.getText() );
System.out.println( "Alignment of lb3 : " + third.getAlignment() );
//getAlignment() override한,정렬방식 리턴시킴~
//프레임에 Label object를 붙임
frame.add( first, "North" ); //첫글자대문자로!
frame.add( second, "Center" ); //첫글자대문자로!
frame.add( third, "South" ); //첫글자대문자로!
//프레임의 사이즈를 결정하고, 화면에 output
frame.setSize( 300, 100 );
frame.setVisible( true );
}
public static void main( String[] args ) {
LabelTest lt = new LabelTest();
}
}


//new operator로 objectdefinition -> set으로 속성변경 ->c ontainerobject에 add!!!

  • Open in Google Docs Viewer
  • Open link in new tab
  • Open link in new window
  • Open link in new incognito window
  • Download file
  • Copy link address
  • Edit PDF File on PDFescape.com
  • Open in Google Docs Viewer
  • Open link in new tab
  • Open link in new window
  • Open link in new incognito window
  • Download file
  • Copy link address
  • Edit PDF File on PDFescape.com

element

Font
font-family
font-size
font-style
font-variant
font-weight
letter-spacing
line-height
text-decoration
text-align
text-indent
text-transform
white-space
word-spacing
color
Background
bg-attachment
bg-color
bg-image
bg-position
bg-repeat
Box
width
height
border-top
border-right
border-bottom
border-left
margin
padding
max-height
min-height
max-width
min-width
outline-color
outline-style
outline-width
Positioning
position
top
bottom
right
left
float
display
clear
z-index
List
list-style-image
list-style-type
list-style-position
Table
vertical-align
border-collapse
border-spacing
caption-side
empty-cells
table-layout
Effects
text-shadow
-webkit-box-shadow
border-radius
Other
overflow
cursor
visibility

element

Font
font-family
font-size
font-style
font-variant
font-weight
letter-spacing
line-height
text-decoration
text-align
text-indent
text-transform
white-space
word-spacing
color
Background
bg-attachment
bg-color
bg-image
bg-position
bg-repeat
Box
width
height
border-top
border-right
border-bottom
border-left
margin
padding
max-height
min-height
max-width
min-width
outline-color
outline-style
outline-width
Positioning
position
top
bottom
right
left
float
display
clear
z-index
List
list-style-image
list-style-type
list-style-position
Table
vertical-align
border-collapse
border-spacing
caption-side
empty-cells
table-layout
Effects
text-shadow
-webkit-box-shadow
border-radius
Other
overflow
cursor
visibility

This English version was translated by Claude.

친절한 찰쓰씨
Written by
친절한 찰쓰씨

Pleasant Charles — UI/UX researcher at AIT. Keeping notes on design, planning, and slow days here since 2010.

More on the author's page

Keep reading

Renewal

Steadily, for the long haul, without burning out

Mar 31, 2026·9 min
Renewal

Tech-life balance

Feb 7, 2026·3 min
Renewal

Humanality, by Park Jeong-ryeol

Feb 7, 2026·11 min