java有代码加界面 java怎么弄界面( 三 )


String fontName[] = ge.getAvailableFontFamilyNames();
for (int i = 0; ifontName.length; i++){
list.addItem(fontName[i]);
}
//定义字体大小数组,字体大小可以自行定义
int[] fontSize = new int[20];
for (int i = 0; ifontSize.length; i++){
fontSize[i] = i+5;
listSize.addItem(fontSize[i]);
}
list.addItemListener(this);
listSize.addItemListener(this);//为设置字体大小的添加监听器
Container con = getContentPane();
con.setLayout(new FlowLayout());
Box boxH1 = Box.createHorizontalBox(), boxH2 = Box
.createHorizontalBox(), boxH3 = Box.createHorizontalBox();
Box boxBase = Box.createVerticalBox();
boxH1.add(list);
boxH1.add(listSize); //添加字体大小设置到面板中
boxH2.add(text);
boxH3.add(yes);
boxH3.add(cancel);
boxBase.add(boxH1);
boxBase.add(boxH2);
boxBase.add(boxH3);
con.add(boxBase);
setBounds(100, 100, 280, 170);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
validate();
}
public void itemStateChanged(ItemEvent e) {
String name = (String) list.getSelectedItem();
Integer size = (Integer) listSize.getSelectedItem(); //获得设置的字体大小
font = new Font(name, Font.PLAIN, size);
text.setFont(font);
text.setText("hello,奥运");
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == yes) {
com.setFont(font);
setVisible(false);
} else if (e.getSource() == cancel) {
setVisible(false);
}
}
}
class Dwindow extends JFrame implements ActionListener {
JTextArea text;
JToolBar bar;
Container con;
JButton buttonFont;
Dwindow() {
buttonFont = new JButton("设置字体");
text = new JTextArea("显示内容");
buttonFont.addActionListener(this);
bar = new JToolBar();
bar.add(buttonFont);
con = getContentPane();
con.add(bar, BorderLayout.NORTH);
con.add(new JScrollPane(text));
setBounds(60, 60, 300, 300);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == buttonFont) {
FontDialog dialog = new FontDialog(text);
dialog.setVisible(true);
}
}
}
public class DialogExample {
public static void main(String args[]) {
new Dwindow();
}
}
Java一个简单程序,求大神帮我在输入输出的地方加个简单的界面,代码如下:能加一个判断姓名不能重复的吗import java.awt.*;
import java.awt.event.*;
public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter");
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
});
}
}
关于java有代码加界面和java怎么弄界面的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

推荐阅读