import java.awt.BorderLayout; import javax.swing.JWindow; import javax.swing.ImageIcon; import javax.swing.JList; import javax.swing.JScrollPane; /* * Copyright 2009-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Description: * <br/>网站: <a href="http://www.crazyit.org" mce_href="http://www.crazyit.org">疯狂Java联盟</a> * <br/>Program Name: FaceWindow.java * <br/>Project Name: netgame * <br/>Date: 2010-2-6 * @author : leeyohn * @e-mail : leeyohn@hotmail.com * @QQ : 1417515725 * @version : 1.0 */ public final class FaceWindow extends JWindow { //表情图片的数量 private static final int FACE_COUNT = 120; //表情窗口的宽度长度 private static final int FACE_WINDOW_WIDTH = 360; private static final int FACE_WINDOW_HEIGHT = 192; //静态表情图片数组 private ImageIcon[] faces = new ImageIcon[FACE_COUNT]; private JList faceList = new JList(faces); //加载所有表情图片 private void initImage() { for (int i = 0; i < FACE_COUNT; i++) { faces[i] = new ImageIcon("face/" + i + ".gif"); } } public FaceWindow() { initImage(); add(new JScrollPane(faceList), BorderLayout.CENTER); faceList.setLayoutOrientation(JList.HORIZONTAL_WRAP); //设置表情列表可显示的行数 faceList.setVisibleRowCount(8); setSize(FACE_WINDOW_WIDTH + 35, FACE_WINDOW_HEIGHT + 21); setLocation(600, 480); } public static void main(String[] args) { new FaceWindow().setVisible(true); } }