java面板,标签,布局问题代码执行
importjava.awt.BorderLayout;importjava.awt.CardLayout;importjava.awt.Font;importjavax...
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TestPanel extends JFrame{
JPanel jpframe;
CardLayout clyout;
public TestPanel(){
JFrame jf=new JFrame();
jf.setVisible(true);
jf.setSize(600,400);
jf.setDefaultCloseOperation(3);
jpframe=new JPanel();
clyout=new CardLayout();
final JPanel jpmain=new JPanel(new BorderLayout());
final JLabel jlmain=new JLabel("你好");
jlmain.setFont(new Font("Serif",Font.BOLD,30));
jpframe.add(jpmain);
jpmain.add(jlmain);
jpframe.add(jpmain,"main");
clyout.show(jpframe,"main");
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new TestPanel();
}
} 展开
import java.awt.CardLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TestPanel extends JFrame{
JPanel jpframe;
CardLayout clyout;
public TestPanel(){
JFrame jf=new JFrame();
jf.setVisible(true);
jf.setSize(600,400);
jf.setDefaultCloseOperation(3);
jpframe=new JPanel();
clyout=new CardLayout();
final JPanel jpmain=new JPanel(new BorderLayout());
final JLabel jlmain=new JLabel("你好");
jlmain.setFont(new Font("Serif",Font.BOLD,30));
jpframe.add(jpmain);
jpmain.add(jlmain);
jpframe.add(jpmain,"main");
clyout.show(jpframe,"main");
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new TestPanel();
}
} 展开
1个回答
展开全部
jpframe.setLayout (clyout);
加这句就好了
加这句就好了
更多追问追答
追答
没问题啊,复制粘贴即可
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TestPanel extends JFrame
{
JPanel jpframe;
CardLayout clyout;
public TestPanel ()
{
JFrame jf = new JFrame ();
jf.setVisible (true);
jf.setSize (600, 400);
jf.setDefaultCloseOperation (3);
jpframe = new JPanel ();
clyout = new CardLayout ();
final JPanel jpmain = new JPanel (new BorderLayout ());
final JLabel jlmain = new JLabel ("你好");
jlmain.setFont (new Font ("Serif", Font.BOLD, 30));
jpframe.add (jpmain);
jpmain.add (jlmain);
jpframe.add (jpmain, "main");
jpframe.setLayout (clyout);
clyout.show (jpframe, "main");
}
public static void main ( String[] args )
{
// TODO 自动生成方法存根
new TestPanel ();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询