http://oldsite.linuxaid.com.cn/developer/showdev.jsp?i=483
这是讲而已的,看看!!
这是讲而已的,看看!!
解决方案 »
- swt 添加数据库记录 assertion failed: ContentViewer must have a content provider when input is set.
- 提示错误,找不出来,请高手帮忙
- java连接sql2005的问题
- 用BufferedInputStream进行数据流的读取时为何总是有数据包丢失?
- 高手帮我看看!!
- Servlet放在哪里
- ListCellRenderer 是做什么用的?
- 我刚学,不知哪个能指导一下
- 请问如果把字符串“1234”转换成INT型的呢?谢谢
- 求如何在其他类中调用自定义异常类中的异常处理方法
- java app in linux
- 提示 :Exception in thread "main" java.lang.NoClassDefFoundError 应该怎么解决
实际运行若写成0,就跑到旁边去了。
@version 1.30 2000-05-12
@author Cay Horstmann
*/import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;public class FontDialog
{
public static void main(String[] args)
{
FontDialogFrame frame = new FontDialogFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}/**
A frame that uses a grid bag layout to arrange font
selection components.
*/
class FontDialogFrame extends JFrame
{
public FontDialogFrame()
{
setTitle("FontDialog");
setSize(WIDTH, HEIGHT); Container contentPane = getContentPane();
GridBagLayout layout = new GridBagLayout();
contentPane.setLayout(layout); ActionListener listener = new FontAction(); // construct components
JLabel faceLabel = new JLabel("Face: "); face = new JComboBox(new String[]
{
"Serif", "SansSerif", "Monospaced",
"Dialog", "DialogInput"
});
face.addActionListener(listener); JLabel sizeLabel = new JLabel("Size: "); size = new JComboBox(new String[]
{
"8", "10", "12", "15", "18", "24", "36", "48"
}); size.addActionListener(listener); bold = new JCheckBox("Bold");
bold.addActionListener(listener); italic = new JCheckBox("Italic");
italic.addActionListener(listener); sample = new JTextArea();
sample.setText(
"The quick brown fox jumps over the lazy dog");
sample.setEditable(false);
sample.setLineWrap(true);
sample.setBorder(BorderFactory.createEtchedBorder()); // add components to grid GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.EAST;
constraints.weightx = 0;
constraints.weighty = 0; add(faceLabel, constraints, 0, 0, 1, 1);
add(sizeLabel, constraints, 0, 1, 1, 1); constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 100;
add(face, constraints, 1, 0, 1, 1);
add(size, constraints, 1, 1, 1, 1); constraints.weighty = 100;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor = GridBagConstraints.CENTER; add(bold, constraints, 0, 2, 2, 1);//这里要是改成 1,2,2,1,就会错位
add(italic, constraints, 0, 3, 2, 1); constraints.fill = GridBagConstraints.BOTH;
add(sample, constraints, 2, 0, 1, 4);
}
/**
A convenience method to add a component to given grid bag
layout locations.
@param c the component to add
@param constraints the grid bag constraints to use
@param x the x grid position
@param y the y grid position
@param w the grid width
@param h the grid height
*/
public void add(Component c, GridBagConstraints constraints,
int x, int y, int w, int h)
{
constraints.gridx = x;
constraints.gridy = y;
constraints.gridwidth = w;
constraints.gridheight = h;
getContentPane().add(c, constraints);
} public static final int WIDTH = 300;
public static final int HEIGHT = 200; private JComboBox face;
private JComboBox size;
private JCheckBox bold;
private JCheckBox italic;
private JTextArea sample; /**
An action listener that changes the font of the
sample text.
*/
private class FontAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String fontFace = (String)face.getSelectedItem();
int fontStyle = (bold.isSelected() ? Font.BOLD : 0)
+ (italic.isSelected() ? Font.ITALIC : 0);
int fontSize = Integer.parseInt(
(String)size.getSelectedItem());
Font font = new Font(fontFace, fontStyle, fontSize);
sample.setFont(font);
sample.repaint();
}
}
}
----------------------
《CSDN论坛新助手 CSDN's forum Explorer》
1、更快速的浏览
2、更方便地保存
3、更快捷的收/发短信
下载地址:http://www.seeyou.com.cn/CoolSlob/CSDNExplorer.exe
更多说明:http://community.csdn.net/Expert/TopicView.asp?id=3255966
表示没有行限制,只能有两列