问一个关于jpanel的问题。。

lodestar51 2004-08-30 01:14:55
jpanel是一个容器吧?它为什么一定还要放到别的容器里呀??
给个例子吧??在说说为什么!!
jframe我明白,可是jpanel晕了。。。。
以前没有做过gui,向大家学习一下。。。
...全文
103 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
oioioi-090 2004-09-01
  • 打赏
  • 举报
回复
因为我用过delphi
我就把JPanel当成TPanel
把JFrame当成TForm

呵呵!不知对不!
oioioi-090 2004-09-01
  • 打赏
  • 举报
回复
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
* Created on 2004-8-28
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author zhu_hb
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class MySwing extends JFrame {
Panel p;
JRadioButton b1 = new JRadioButton("Metal"),
b2 = new JRadioButton("Motif"),
b3 = new JRadioButton("Windows");
public MySwing() {
super("Swing application");
Container contentPane = getContentPane();
p = new Panel();
contentPane.add(p, BorderLayout.CENTER);
}
public static void main(String[] args) {
final JFrame f = new MySwing();
f.setBounds(100, 100, 300, 200);
f.setVisible(true);
f.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
class Panel extends JPanel implements ActionListener {
public Panel() {
add(new JButton("JButton"));
add(new JTextField("JTextField"));
add(new JCheckBox("JCheckBox"));
add(new JRadioButton("JRadioButton"));
add(new JLabel("JLabel"));
add(
new JList(
new String[] {
"JList Item 1",
"JList Item 2",
"JList Item 3" }));
add(new JScrollBar(SwingConstants.HORIZONTAL));
ButtonGroup group = new ButtonGroup();
group.add(b1);
group.add(b2);
group.add(b3);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(b1);
add(b2);
add(b3);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("Hello from Eclipse!", 60, 100);
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
JRadioButton src = (JRadioButton) e.getSource();
try {
if ((JRadioButton) e.getSource() == b1)
UIManager.setLookAndFeel(
"javax.swing.plaf.metal.MetalLookAndFeel");
else if ((JRadioButton) e.getSource() == b2)
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.motif.MotifLookAndFeel");
else if ((JRadioButton) e.getSource() == b3)
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
}
SwingUtilities.updateComponentTreeUI(getContentPane());
}
}
}
lodestar51 2004-09-01
  • 打赏
  • 举报
回复
UP.....一下。。。过两天结贴。。
有没有人给个JPanel的CODE呀?
谢谢了。。
sylmoon 2004-08-30
  • 打赏
  • 举报
回复
jframe是最低层的容器,相当于构建一个windows窗口
jpanel是窗口中的容器,用来容纳各种其他的组件
并可以使用很多工具来增强表现力
如:layout,doublebuffer等
flyingbug 2004-08-30
  • 打赏
  • 举报
回复
jframe是最低层的容器,相当于构建一个windows窗口
jpanel是窗口中的容器,用来容纳各种其他的组件
并可以使用很多工具来增强表现力
如:layout,doublebuffer等
constantine 2004-08-30
  • 打赏
  • 举报
回复
up
zerogotosum 2004-08-30
  • 打赏
  • 举报
回复
看书

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧