社区
Java SE
帖子详情
问一个关于jpanel的问题。。
lodestar51
2004-08-30 01:14:55
jpanel是一个容器吧?它为什么一定还要放到别的容器里呀??
给个例子吧??在说说为什么!!
jframe我明白,可是jpanel晕了。。。。
以前没有做过gui,向大家学习一下。。。
...全文
143
7
打赏
收藏
问一个关于jpanel的问题。。
jpanel是一个容器吧?它为什么一定还要放到别的容器里呀?? 给个例子吧??在说说为什么!! jframe我明白,可是jpanel晕了。。。。 以前没有做过gui,向大家学习一下。。。
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用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
打赏
举报
回复
看书
Java Swing 在
一个
JFrame框架中使用多个
JPanel
面板布局的方法(不同
JPanel
不覆盖)
Java Swing 在
一个
JFrame框架中使用多个
JPanel
面板布局的方法(不同
JPanel
不覆盖) 在最近的对Java Swing的学习中,按照要求对
一个
界面中添加不同功能且排布整齐的控件时,不同
JPanel
之间会产生覆盖,总结了
JPanel
添加且不进行覆盖的方法 实现代码如下 public class
JPanel
TEST{ private JFrame jf; private
JPanel
jp,jp1,jp2; //若想要实现添加到同一JFrame中且不覆盖,不可直接添加,需要先将要添加
java
jpanel
刷新_
JPanel
重绘
问
题
JPanel
重绘
问
题
我有
一个
JFrame,其中包含2个
JPanel
子类和BorderLayout中的2个JLabel。其中
一个
JPanel
包含JButtons,另
一个
用于显示图形。JLabels位于北部和南部,西部是
JPanel
按钮,中间是
JPanel
。显示
JPanel
需要不断刷新,所以我通过swing计时器生成的动作事件调用它的repaint()方法。我也覆盖它的paintComponent()...
java
jpanel
叠加_java
JPanel
重叠覆盖
问
题
。
importjava.awt.Graphics;importjavax.swing.JFrame;importjavax.swing.
JPanel
;publicclasspaintextendsJFrame{
JPanel
jp1;
JPanel
jp2;publicpaint(){this.add(jp1=newpanel1());jp1.se...import java.awt.Graphics;im...
jpane1_如何用另
一个
JPanel
替换
JPanel
我想用JFrame中的另
一个
替换
Jpanel
我已经搜索并尝试了我的代码,但没有任何事情发生这是我的代码:public class Frame extends JFrame {private Container contain;private
JPanel
reChange,reChange2;private JButton reChangeButton;public Frame() {super(...
java
jpanel
叠加_java – 在
一个
JFrame中同时处理两个
JPanel
我是java swing的新手.在尝试使用图形时,我会遇到这种情况.我无法在网络上找到合适的解决方案.所以我想发布在这里.所以现在让我们来解决我的
问
题
.首先,我将解释我想做什么.然后我将解释我的
问
题
.我试图让两个球在JFrame中同时向不同的方向移动. (基本上我想做类似连锁反应的游戏,当你点击
一个
装满的盒子时,球会同时向不同的方向移动).这里我创建两个(截至目前)两个球的
JPanel
s,我试图同...
Java SE
62,620
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章