file_select.java
more..
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Rectangle;
import java.io.IOException;
import java.awt.event.*;
import javax.media.*;
import javax.media.protocol.*;
import javax.tv.xlet.*;
import org.havi.ui.*;
import org.havi.ui.HStaticText;
import org.havi.ui.HDefaultTextLayoutManager;
import org.havi.ui.event.*;
import java.awt.Container.*;
import java.io.File;
public class file_select
extends HContainer {
private int focous_pos;
private MenuItemBox tempBox;
private String f_list[] = null;
public int pos;
private File f = new File("./files/");
private int itemHeight;
public file_select(){
super();
pos = 0;
setSize(720, 576);
setLocation(0,0);
f_list = f.list(null);
//int itemHeight = height/ f_list.length;
try{
for(int i = 0; i < f_list.length ; i++){
tempBox = new MenuItemBox(100,i*45+2,500,35,f_list[i]);
//tempBox.setSize(500,35);
add(tempBox);
//tempBox.setVisible(true);
}
((MenuItemBox)getComponent(0)).setFocused(true);
tempBox.setVisible(true);
setVisible(true);
}catch (NullPointerException e)
{
}
}
public String get_filename(){
return f_list[pos];
}
public void pos_up(){
f_list = f.list(null);
pos = (pos + f_list.length - 1 ) % f_list.length ;
moving();
}
public void pos_down(){
//pos--;
f_list = f.list(null);
pos = (pos + f_list.length + 1 ) % f_list.length ;
moving();
}
public void moving(){
for(int i = 0; i < f_list.length ; i++){
((MenuItemBox)getComponent(i)).setFocused(false);
tempBox.setVisible(true);
}
((MenuItemBox)getComponent(pos)).setFocused(true);
this.repaint();
}
}// class
MenuItemBox.java
more..
import java.awt.*;
public class MenuItemBox extends Component {
private int width = 0;
private int height = 0;
private boolean focused = false;
public String getname;
public MenuItemBox(int x,int y,int w, int h, String setname) {
super();
setLocation(x,y);
setSize(w,h);
width = w;
height = h;
getname = setname;
//paint(null);
//focused = focuse;
}
public void paint(Graphics g) {
g.setColor(Color.black);
g.fillRect(0,0,width,height);
if (focused) {
g.setColor(new Color(0xff, 0xff, 0xff));
g.fillRect(2,2,width-4,height-4);
g.setColor(Color.black);
} else {
g.setColor(new Color(0x55,0x55,0x55));
g.fillRect(2,2,width-4,height-4);
g.setColor(Color.white);
}
g.setFont(new Font("Tireasias",Font.PLAIN,20));
FontMetrics fm = g.getFontMetrics();
int txtHeight = fm.getHeight();
int txtWidth = fm.stringWidth(getname);
g.drawString(getname,(width-txtWidth)/2,height/2+(int)(txtHeight/3));
}
public void setFocused(boolean b) {
if (b) {
focused = true;
} else {
focused = false;
}
}
}
댓글 없음:
댓글 쓰기