import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.io.*;
import java.util.*;
public class GridBagLab extends JFrame {
static String lastFile = null;
static ConstraintsPanel cp;
static JTextArea helpTextArea =
new JTextArea(contentsOfFile("intro.txt"));
JDesktopPane desktop = new JDesktopPane();
JInternalFrame buttonsFrame =
new JInternalFrame("Buttons", true, false, true, false);
JInternalFrame constraintsFrame =
new JInternalFrame("Constraints", false, false, true, true);
JInternalFrame helpFrame =
new JInternalFrame("GridBag Constraints Explained", true, false, true, true);
final GridBagLayout gbl = new GridBagLayout();
ButtonGroup group = new ButtonGroup();
JToggleButton selected = null;
JToggleButton oneButton = new JToggleButton(),
twoButton = new JToggleButton(),
threeButton = new JToggleButton(),
fourButton = new JToggleButton(),
fiveButton = new JToggleButton(),
sixButton = new JToggleButton(),
sevenButton = new JToggleButton(),
eightButton = new JToggleButton(),
nineButton = new JToggleButton(),
tenButton = new JToggleButton();
public GridBagLab() {
super("GridBag Lab");
JMenuBar mb = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem aboutItem = new JMenuItem("about ...");
JMenuItem quitItem = new JMenuItem("quit");
final AboutDialog aboutDialog = new AboutDialog(this);
fileMenu.add(aboutItem);
fileMenu.add(quitItem);
mb.add(fileMenu);
setJMenuBar(mb);
aboutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Point loc = getLocation();
aboutDialog.pack();
aboutDialog.setLocation(loc.x + 100, loc.y + 100);
aboutDialog.setVisible(true);
}
});
quitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
GridBagConstraints gbc = new GridBagConstraints();
ButtonListener listener = new ButtonListener();
oneButton.setIcon(new ImageIcon("gifs/one.gif"));
oneButton.addActionListener(listener);
twoButton.setIcon(new ImageIcon("gifs/two.gif"));
twoButton.addActionListener(listener);
threeButton.setIcon(new ImageIcon("gifs/three.gif"));
threeButton.addActionListener(listener);
fourButton.setIcon(new ImageIcon("gifs/four.gif"));
fourButton.addActionListener(listener);
fiveButton.setIcon(new ImageIcon("gifs/five.gif"));
fiveButton.addActionListener(listener);
sixButton.setIcon(new ImageIcon("gifs/six.gif"));
sixButton.addActionListener(listener);
sevenButton.setIcon(new ImageIcon("gifs/seven.gif"));
sevenButton.addActionListener(listener);
eightButton.setIcon(new ImageIcon("gifs/eight.gif"));
eightButton.addActionListener(listener);
nineButton.setIcon(new ImageIcon("gifs/nine.gif"));
nineButton.addActionListener(listener);
tenButton.setIcon(new ImageIcon("gifs/ten.gif"));
tenButton.addActionListener(listener);
oneButton.setFocusPainted(false);
twoButton.setFocusPainted(false);
threeButton.setFocusPainted(false);
fourButton.setFocusPainted(false);
fiveButton.setFocusPainted(false);
sixButton.setFocusPainted(false);
sevenButton.setFocusPainted(false);
eightButton.setFocusPainted(false);
nineButton.setFocusPainted(false);
tenButton.setFocusPainted(false);
group.add(oneButton);
group.add(twoButton);
group.add(threeButton);
group.add(fourButton);
group.add(fiveButton);
group.add(sixButton);
group.add(sevenButton);
group.add(eightButton);
group.add(nineButton);
group.add(tenButton);
Container contentPane = getContentPane();
desktop.add(buttonsFrame);
desktop.add(constraintsFrame);
desktop.add(helpFrame);
contentPane.setLayout(new BorderLayout());
contentPane.add(desktop, "Center");
JPanel buttonsPanel = new JPanel();
buttonsFrame.getContentPane().add(buttonsPanel, "Center");
buttonsPanel.setLayout(gbl);
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.gridy = 0;
buttonsPanel.add(oneButton, gbc);
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = 0;
buttonsPanel.add(twoButton, gbc);
buttonsPanel.add(threeButton, gbc);
gbc.gridx = 0;
gbc.gridy = GridBagConstraints.RELATIVE;
buttonsPanel.add(fourButton, gbc);
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = 1;
buttonsPanel.add(fiveButton, gbc);
buttonsPanel.add(sixButton, gbc);
gbc.gridx = 0;
gbc.gridy = GridBagConstraints.RELATIVE;
buttonsPanel.add(sevenButton, gbc);
gbc.gridx = GridBagConstraints.RELATIVE;
gbc.gridy = 2;
buttonsPanel.add(eightButton, gbc);
buttonsPanel.add(nineButton, gbc);
gbc.gridx = 0;
gbc.gridy = GridBagConstraints.RELATIVE;
buttonsPanel.add(tenButton, gbc);
Container constraintsPane = constraintsFrame.getContentPane();
constraintsPane.add(cp = new ConstraintsPanel());
//constraintsFrame.pack();
constraintsFrame.setSize(250,600);
Dimension constraintsSize = constraintsFrame.getSize();
setBounds(300,100,500, constraintsSize.height);
Point buttonsLocation = buttonsFrame.getLocation();
Dimension buttonsSize = buttonsFrame.getSize();
buttonsFrame.setBounds(0,0,350,350);
helpFrame.setBounds(0,352,350+constraintsSize.width,buttonsFrame.getSize().height+2);
helpTextArea.setWrapStyleWord(true);
helpTextArea.setEditable(false);
helpTextArea.setFont(
new Font("Times-Roman", Font.PLAIN, 12));
helpFrame.getContentPane().add(
new JScrollPane(helpTextArea),
"Center");
}
public void setHelpViewer(String filename) {
if(lastFile == null || !lastFile.equals(filename)) {
helpTextArea.setText(contentsOfFile(filename));
lastFile = filename;
}
}
public void setConstraints(GridBagConstraints gbc) {
if(selected != null) {
gbl.setConstraints(selected, gbc);
selected.invalidate();
validate();
}
}
public GridBagConstraints getConstraints() {
GridBagConstraints gbc = null;
if(selected != null)
gbc = gbl.getConstraints(selected);
return gbc;
}
class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
selected = (JToggleButton)e.getSource();
cp.setConstraints(gbl.getConstraints(selected));
}
}
static String contentsOfFile(String filename) {
String s = new String();
File f;
char[] buff = new char[50000];
InputStream is;
InputStreamReader reader;
URL url;
try {
f = new File(filename);
reader = new FileReader(f);
int nch;
while ((
nch = reader.read(buff, 0, buff.length)) != -1) {
s = s + new String(buff, 0, nch);
}
}
catch (java.io.IOException ex) {
s = "Could not load file: " + filename;
}
return s;
}
class ConstraintsDialog extends JInternalFrame {
public ConstraintsDialog(GridBagLab test) {
super("GridBagConstraints");
getContentPane().add(new ConstraintsPanel());
}
}
class ConstraintsPanel extends JPanel {
AnchorFillWeightPanel afpanel = new AnchorFillWeightPanel();
DisplayAreaPanel dpanel = new DisplayAreaPanel();
PaddingPanel ppanel = new PaddingPanel();
InsetsPanel ipanel = new InsetsPanel();
String dpaneltip = "display area attributes",
afpaneltip = "component attributes",
ppaneltip = "padding";
public ConstraintsPanel() {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(dpanel);
add(Box.createVerticalStrut(15));
add(afpanel);
add(Box.createVerticalStrut(15));
add(ppanel);
add(Box.createVerticalStrut(15));
add(ipanel);
add(Box.createVerticalStrut(15));
}
public void setConstraints
没有合适的资源?快使用搜索试试~ 我知道了~
java2 swing 源代码
共2000个文件
class:1230个
java:319个
html:244个
需积分: 0 2 下载量 75 浏览量
2009-09-25
12:47:55
上传
评论
收藏 4.31MB ZIP 举报
温馨提示
java2 swing 源代码, java2 swing 源代码, java2 swing 源代码
资源详情
资源评论
资源推荐
收起资源包目录
java2 swing 源代码 (2000个子文件)
Test.java.bak 3KB
GridBagLab.class 8KB
ElementTreePanel.class 8KB
ElementTreePanel.class 8KB
GridBagLab.class 7KB
GridBagLab$AnchorFillWeightPanel.class 6KB
GridBagLab$DisplayAreaPanel.class 6KB
AnchorFillWeightPanel.class 6KB
Test.class 6KB
DisplayAreaPanel.class 6KB
Test.class 6KB
Test.class 5KB
AnchorFillWeightPanel.class 5KB
DisplayAreaPanel.class 5KB
Test.class 5KB
ControlPanel.class 4KB
Test.class 4KB
AnimationPane.class 4KB
AbstractCellEditor.class 4KB
AbstractCellEditor.class 4KB
StereoDeckModel.class 4KB
Test.class 4KB
Test.class 4KB
StereoDeckModel.class 4KB
DebugGraphicsTest.class 4KB
Test.class 4KB
Test.class 3KB
Test.class 3KB
ListPanel.class 3KB
Test.class 3KB
AbstractCellEditor.class 3KB
UnderlineElement.class 3KB
Test.class 3KB
SSPanel.class 3KB
Test.class 3KB
CustomContentPane.class 3KB
PopOutButtonUI.class 3KB
Test.class 3KB
Test.class 3KB
GridBagLab$ConstraintsPanel.class 3KB
GridBagLab$PaddingPanel.class 3KB
OutlineManager.class 3KB
Test.class 3KB
ButtonPurchaseForm.class 3KB
Test.class 3KB
Test.class 3KB
Test.class 3KB
GridBagLab$InsetsPanel.class 3KB
Test.class 3KB
Test.class 3KB
Test.class 3KB
SortDecorator.class 3KB
ConstraintsPanel.class 3KB
Test$ControlPanel.class 3KB
ConstraintsPanel.class 3KB
Test$1.class 3KB
ClientPropertiesTest.class 3KB
Test$ForegroundFromChooserAction.class 3KB
InsetsPanel.class 3KB
SelfModifyingMenu.class 3KB
PaddingPanel.class 3KB
AllBordersPanel.class 3KB
Test.class 3KB
Test.class 3KB
TestApplet.class 3KB
FileNodeRenderer.class 3KB
Test.class 3KB
TableCellVolumeRenderer.class 3KB
Test.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
ColorKeySelectionManager.class 3KB
Test$2.class 3KB
GJApp.class 3KB
Test.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
GJApp.class 3KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
zeno_zy
- 粉丝: 25
- 资源: 25
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0