| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Emmet
- GitHub 미러링
- GitLab Mirroring
- visual studio code cli
- code 설치
- 니돈내먹
- 네이버 클라우드 플랫폼
- gitlab 연동
- GitHub Mirroring
- visual studio code
- 프리티어
- 유니옥션
- GitLab미러링
- eslint-import-resolver-typescript
- Path Alias
- 티스토리 초대장/ 티스토리초대
- 티스토리초대
- webstorm
- settings sync
- 티스토리 초대장
- 실행시간 측정
- 초대장
- '티스토리 초대장/ 티스토리초대'
- code 세팅
- react native #gradle
- code .
- 음료같은녹즙
- React Native
- currentTimeMillis
- 프레시업 #풀무원 #하루한병 #건강만들기 #풀무원 녹즙
Archives
- Today
- Total
방치하기
홍대 자바 수업 : 리스트형(스크롤형) 버튼 텍스트 필드 컬러와 배경 색 바꾸기 . 본문
반응형
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
public class ListTest extends JFrame {
private JTextField text;
private JList colorList;
Random ra =new Random(System.currentTimeMillis());
private Container container;
private final String colorNames[] = { "Black", "Blue", "Cyan",
"Dark Gray", "Gray", "Green", "Light Gray", "Magenta",
"Orange", "Pink", "Red", "White", "Yellow" };
private final Color colors[] = { Color.BLACK, Color.BLUE, Color.CYAN,
Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY,
Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE,
Color.YELLOW };
public ListTest()
{
super( "Color Test" );
container = getContentPane();
container.setLayout( new FlowLayout() );
colorList = new JList( colorNames );
colorList.setVisibleRowCount( 5 ); //보이는 버튼수
colorList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );//하나만 선택
container.add( new JScrollPane( colorList ) );
text=new JTextField(10);
container.add(text);
text.setFont( new Font( "굴림체", Font.PLAIN,38) );//폰트 체 등등 .
colorList.addListSelectionListener(
new ListSelectionListener() { // anonymous inner class
public void valueChanged( ListSelectionEvent event )
{
int a =ra.nextInt(13);//난수
text.setText(colorNames[colorList.getSelectedIndex()]);
container.setBackground(colors [ colorList.getSelectedIndex() ]);//colorList.getSelectedIndex().toString(); text.setBackground(
colors[ a ] );
if (a>=12)
{
text.setForeground(
colors[ a-6 ] );
}
else
{
text.setForeground(
colors[ a+1 ] );
}
}
} // end anonymous inner class
); // end call to addListSelectionListener
setSize( 350, 150 );
setVisible( true );
} // end ListTest constructor
public static void main( String args[] )
{
ListTest application = new ListTest();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
} // end class ListTest
//리스트 목록 뽑아 오기
for (int i=0; i
System.out.println(colorList.getModel().getElementAt(i).toString());
}
반응형
'홍익대 Java > 수업' 카테고리의 다른 글
| 키이벤트 (0) | 2009.07.30 |
|---|---|
| 홍대 자바 수업 계산기임 Model / View /Control Float.parseFloat (0) | 2009.07.30 |
| 텍스트 필드와 버튼 (0) | 2009.07.29 |
| swing label textfield (0) | 2009.07.28 |
| 홍대 자바 수업 : awt 버튼 원하는 자리에 (0) | 2009.07.28 |
Comments