用java怎么编出下面的窗口界面?急啊,谢谢了
可以只说明这个窗口界面是怎么做的,里面的各个下拉选项栏,按钮怎么安排上去的,还有那个excel怎么添加进去的,其他的我自己可以实现,谢谢了...
可以只说明这个窗口界面是怎么做的,里面的各个下拉选项栏,按钮怎么安排上去的,还有那个excel怎么添加进去的,其他的我自己可以实现,谢谢了
展开
2个回答
2011-02-24
展开全部
首先注意到没有最大化和最小化,那么是个JDialog.
左上角图标换了,用JDialog的setIconImage方法来设置。
内部上面定高,下面填满高。用BorderLayout,上JPanel,下JPanel
上JPanel竖排,用BoxLayout,里面两个JPanel
两个JPanel设置边框,用TitledBorder.然后显然是GridLayout.每个里面JPanel
每个JPanel输入部分定宽,左边拉伸,用BorderLayout,右为JTextField或者JComboBox,左JLabel
下JPanel设置边框,用TitledBorder.内部是JScrollPane套一个JTable,不是什么Excel,另外JTable是极度复杂极度强大的,多花点时间学它的源代码比较好
-----------------觉得有点复杂,你初学的话可能搞不定,试着帮你写了一个,尽量看懂吧--------
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
class Test {
private static JDialog window;
private static JTextField s1;
private static JTextField s2;
private static JComboBox s3;
private static JComboBox s4;
private static JComboBox s5;
private static JComboBox s6;
private static JComboBox s7;
private static JComboBox c1;
private static JComboBox c2;
private static JComboBox c3;
private static JComboBox c4;
private static JComboBox c5;
private static JPanel tableRstContainer;
private static final int LINE_HEIGHT = 22;
private static void searchAction() {
JOptionPane.showMessageDialog(window, "自己根据s1-s7和c1-c5生成data");
Object[][] data = new Object[][] {
new Object[] {"编码1", "曲名1"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
};
JTable tableRst = new JTable(data, new String[] {"编码", "曲名"});
tableRstContainer.removeAll();
tableRstContainer.add(new JScrollPane(tableRst));
tableRstContainer.validate();
tableRstContainer.revalidate();
tableRstContainer.repaint();
}
private static void resetAction() {
JOptionPane.showMessageDialog(window, "自己写Reset吧");
}
private static void fixSize(JComponent component, int w, int h) {
Dimension size = new Dimension(w, h);
component.setMaximumSize(size);
component.setMinimumSize(size);
component.setPreferredSize(size);
component.setSize(size);
}
private static JComponent addInput(String title, JComponent component, int widthL, int widthC, boolean isTF) {
JPanel pane = new JPanel(new BorderLayout());
fixSize(component, widthC, LINE_HEIGHT);
pane.add(component, BorderLayout.CENTER);
JLabel label = new JLabel(title);
fixSize(label, widthL, LINE_HEIGHT);
pane.add(label, BorderLayout.WEST);
pane.add(component, BorderLayout.CENTER);
pane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
if (isTF) {
((JTextField) component).getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
searchAction();
}
@Override
public void insertUpdate(DocumentEvent e) {
searchAction();
}
@Override
public void removeUpdate(DocumentEvent e) {
searchAction();
}
});
} else {
((JComboBox) component).addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
searchAction();
}
}
});
}
return pane;
}
public static void main() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable e) {
}
window = new JDialog((Frame) null, "CD查询");
s1 = new JTextField();
s2 = new JTextField();
s3 = new JComboBox(new String[] {"A", "B"});
s4 = new JComboBox(new String[] {"A", "B"});
s5 = new JComboBox(new String[] {"A", "B"});
s6 = new JComboBox(new String[] {"A", "B"});
s7 = new JComboBox(new String[] {"A", "B"});
c1 = new JComboBox(new String[] {"A", "B"});
c2 = new JComboBox(new String[] {"A", "B"});
c3 = new JComboBox(new String[] {"A", "B"});
c4 = new JComboBox(new String[] {"A", "B"});
c5 = new JComboBox(new String[] {"A", "B"});
c1.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Object item = e.getItem();
JOptionPane.showMessageDialog(window, "根据" + item + "来设置c2");
}
}
});
c2.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Object item = e.getItem();
JOptionPane.showMessageDialog(window, "根据" + item + "来设置c3");
}
}
});
window.setIconImage(Toolkit.getDefaultToolkit().getImage("F:\\DRARING\\face\\MSN1.gif"));
window.setLayout(new BorderLayout()); {
JPanel paneLoc = new JPanel(null);
paneLoc.setLayout(new BoxLayout(paneLoc, BoxLayout.Y_AXIS)); {
JPanel paneSub = new JPanel(new GridLayout(2, 4));
paneSub.setBorder(BorderFactory.createTitledBorder("属性"));
paneSub.add(addInput("编码", s1, 50, 70, true));
paneSub.add(addInput("编2", s2, 50, 70, true));
paneSub.add(addInput("编3", s3, 50, 70, false));
paneSub.add(addInput("编4", s4, 50, 70, false));
paneSub.add(addInput("编5", s5, 50, 70, false));
paneSub.add(addInput("编6", s6, 50, 70, false));
paneSub.add(addInput("编7", s7, 50, 70, false));
paneLoc.add(paneSub);
} {
JPanel paneSub = new JPanel(new GridLayout(2, 3));
paneSub.setBorder(BorderFactory.createTitledBorder("分类"));
paneSub.add(addInput("一级分类", c1, 50, 110, false));
paneSub.add(addInput("一级分2", c2, 50, 110, false));
paneSub.add(addInput("一级分3", c3, 50, 110, false));
paneSub.add(addInput("一级分4", c4, 50, 110, false));
paneSub.add(addInput("一级分5", c5, 50, 110, false));
JPanel paneReset = new JPanel(new FlowLayout(FlowLayout.LEADING, 2, 0));
JButton btnReset = new JButton("重置");
btnReset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resetAction();
}
});
paneReset.add(btnReset);
paneSub.add(paneReset);
paneLoc.add(paneSub);
}
window.add(paneLoc, BorderLayout.NORTH);
} {
tableRstContainer = new JPanel();
tableRstContainer.setBorder(BorderFactory.createTitledBorder("关联CD"));
window.add(tableRstContainer, BorderLayout.CENTER);
}
window.pack();
window.setSize(new Dimension(window.getWidth(), window.getHeight() + 150));
window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
window.setLocationRelativeTo(null);
window.setVisible(true);
}
}
左上角图标换了,用JDialog的setIconImage方法来设置。
内部上面定高,下面填满高。用BorderLayout,上JPanel,下JPanel
上JPanel竖排,用BoxLayout,里面两个JPanel
两个JPanel设置边框,用TitledBorder.然后显然是GridLayout.每个里面JPanel
每个JPanel输入部分定宽,左边拉伸,用BorderLayout,右为JTextField或者JComboBox,左JLabel
下JPanel设置边框,用TitledBorder.内部是JScrollPane套一个JTable,不是什么Excel,另外JTable是极度复杂极度强大的,多花点时间学它的源代码比较好
-----------------觉得有点复杂,你初学的话可能搞不定,试着帮你写了一个,尽量看懂吧--------
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
class Test {
private static JDialog window;
private static JTextField s1;
private static JTextField s2;
private static JComboBox s3;
private static JComboBox s4;
private static JComboBox s5;
private static JComboBox s6;
private static JComboBox s7;
private static JComboBox c1;
private static JComboBox c2;
private static JComboBox c3;
private static JComboBox c4;
private static JComboBox c5;
private static JPanel tableRstContainer;
private static final int LINE_HEIGHT = 22;
private static void searchAction() {
JOptionPane.showMessageDialog(window, "自己根据s1-s7和c1-c5生成data");
Object[][] data = new Object[][] {
new Object[] {"编码1", "曲名1"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
new Object[] {"编码2", "曲名2"},
};
JTable tableRst = new JTable(data, new String[] {"编码", "曲名"});
tableRstContainer.removeAll();
tableRstContainer.add(new JScrollPane(tableRst));
tableRstContainer.validate();
tableRstContainer.revalidate();
tableRstContainer.repaint();
}
private static void resetAction() {
JOptionPane.showMessageDialog(window, "自己写Reset吧");
}
private static void fixSize(JComponent component, int w, int h) {
Dimension size = new Dimension(w, h);
component.setMaximumSize(size);
component.setMinimumSize(size);
component.setPreferredSize(size);
component.setSize(size);
}
private static JComponent addInput(String title, JComponent component, int widthL, int widthC, boolean isTF) {
JPanel pane = new JPanel(new BorderLayout());
fixSize(component, widthC, LINE_HEIGHT);
pane.add(component, BorderLayout.CENTER);
JLabel label = new JLabel(title);
fixSize(label, widthL, LINE_HEIGHT);
pane.add(label, BorderLayout.WEST);
pane.add(component, BorderLayout.CENTER);
pane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
if (isTF) {
((JTextField) component).getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(DocumentEvent e) {
searchAction();
}
@Override
public void insertUpdate(DocumentEvent e) {
searchAction();
}
@Override
public void removeUpdate(DocumentEvent e) {
searchAction();
}
});
} else {
((JComboBox) component).addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
searchAction();
}
}
});
}
return pane;
}
public static void main() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable e) {
}
window = new JDialog((Frame) null, "CD查询");
s1 = new JTextField();
s2 = new JTextField();
s3 = new JComboBox(new String[] {"A", "B"});
s4 = new JComboBox(new String[] {"A", "B"});
s5 = new JComboBox(new String[] {"A", "B"});
s6 = new JComboBox(new String[] {"A", "B"});
s7 = new JComboBox(new String[] {"A", "B"});
c1 = new JComboBox(new String[] {"A", "B"});
c2 = new JComboBox(new String[] {"A", "B"});
c3 = new JComboBox(new String[] {"A", "B"});
c4 = new JComboBox(new String[] {"A", "B"});
c5 = new JComboBox(new String[] {"A", "B"});
c1.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Object item = e.getItem();
JOptionPane.showMessageDialog(window, "根据" + item + "来设置c2");
}
}
});
c2.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Object item = e.getItem();
JOptionPane.showMessageDialog(window, "根据" + item + "来设置c3");
}
}
});
window.setIconImage(Toolkit.getDefaultToolkit().getImage("F:\\DRARING\\face\\MSN1.gif"));
window.setLayout(new BorderLayout()); {
JPanel paneLoc = new JPanel(null);
paneLoc.setLayout(new BoxLayout(paneLoc, BoxLayout.Y_AXIS)); {
JPanel paneSub = new JPanel(new GridLayout(2, 4));
paneSub.setBorder(BorderFactory.createTitledBorder("属性"));
paneSub.add(addInput("编码", s1, 50, 70, true));
paneSub.add(addInput("编2", s2, 50, 70, true));
paneSub.add(addInput("编3", s3, 50, 70, false));
paneSub.add(addInput("编4", s4, 50, 70, false));
paneSub.add(addInput("编5", s5, 50, 70, false));
paneSub.add(addInput("编6", s6, 50, 70, false));
paneSub.add(addInput("编7", s7, 50, 70, false));
paneLoc.add(paneSub);
} {
JPanel paneSub = new JPanel(new GridLayout(2, 3));
paneSub.setBorder(BorderFactory.createTitledBorder("分类"));
paneSub.add(addInput("一级分类", c1, 50, 110, false));
paneSub.add(addInput("一级分2", c2, 50, 110, false));
paneSub.add(addInput("一级分3", c3, 50, 110, false));
paneSub.add(addInput("一级分4", c4, 50, 110, false));
paneSub.add(addInput("一级分5", c5, 50, 110, false));
JPanel paneReset = new JPanel(new FlowLayout(FlowLayout.LEADING, 2, 0));
JButton btnReset = new JButton("重置");
btnReset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resetAction();
}
});
paneReset.add(btnReset);
paneSub.add(paneReset);
paneLoc.add(paneSub);
}
window.add(paneLoc, BorderLayout.NORTH);
} {
tableRstContainer = new JPanel();
tableRstContainer.setBorder(BorderFactory.createTitledBorder("关联CD"));
window.add(tableRstContainer, BorderLayout.CENTER);
}
window.pack();
window.setSize(new Dimension(window.getWidth(), window.getHeight() + 150));
window.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
window.setLocationRelativeTo(null);
window.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询