问一个关于jpanel的问题。。 jframe是最低层的容器,相当于构建一个windows窗口jpanel是窗口中的容器,用来容纳各种其他的组件并可以使用很多工具来增强表现力如:layout,doublebuffer等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jframe是最低层的容器,相当于构建一个windows窗口jpanel是窗口中的容器,用来容纳各种其他的组件并可以使用很多工具来增强表现力如:layout,doublebuffer等 UP.....一下过两天结贴。。有没有人给个JPanel的CODE呀?谢谢了。。 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()); } }} 因为我用过delphi我就把JPanel当成TPanel 把JFrame当成TForm呵呵!不知对不! 新手求教。。。 高手挑战题!!! java 组合模式 java客户端界面开发 求从数据库查询出表的结果,显示到JSP页面上的一段JAVA代码,多谢 如何让JButton的标签竖着排列 有谁知道怎么用JCreator的帮助 支持java JDBC的数据库软件有那些?那个最好用? 要给一个日期型变量赋一个值该如何写? 如何用socket一次传输多个文件,如何确定文件一个文件结束 applet运行不了,不知道为什么,高手看看。 寻求高手帮助!!
jpanel是窗口中的容器,用来容纳各种其他的组件
并可以使用很多工具来增强表现力
如:layout,doublebuffer等
有没有人给个JPanel的CODE呀?
谢谢了。。
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());
}
}
}
我就把JPanel当成TPanel
把JFrame当成TForm呵呵!不知对不!