Java 将getContentpane与FlowLayout一起使用以应用对布局的更改,但不起作用。为什么?
大家好,我正在尝试用actionListener制作3个按钮(左、中、右),因此当有人单击其中一个按钮时,框架的FlowLayout对齐方式会发生变化,但当我尝试使用getContentpane()方法时,它无法正常工作!这是我的密码:Java 将getContentpane与FlowLayout一起使用以应用对布局的更改,但不起作用。为什么?,java,swing,compiler-errors,awt,cannot-find-symbol,Java,Swing,Compiler Errors,Awt,Cannot Find Symbol,大家好,我正在尝试用actionListener制作3个按钮(左、中、右),因此当有人单击其中一个按钮时,框架的FlowLayout对齐方式会发生变化,但当我尝试使用getContentpane()方法时,它无法正常工作!这是我的密码: import javax.swing.JFrame; import javax.swing.JButton; import java.awt.*; import java.awt.event.*; public class FLowLayoutExample
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.*;
public class FLowLayoutExample extends JFrame implements ActionListener{
public static FlowLayout flowLayout;
public static JButton left,center,right;
public FLowLayoutExample(){
flowLayout = new FlowLayout();
left = new JButton("left");
center = new JButton("center");
right = new JButton("right");
setSize(800,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(flowLayout);
add(left);
add(center);
add(right);
//Register a componentes with the listener
left.addActionListener(this);
center.addActionListener(this);
right.addActionListener(this);
setVisible(true);
}
public static void main(String args[]){
new FLowLayoutExample();
}//End of main method
public void actionPerformed(ActionEvent e){
if(e.getSource() == left){
flowLayout.setAlignment(FlowLayout.LEFT);
}
flowLayout.layoutContainer(getContentpane());
}
}//End of class
我得到了这个错误:
FLowLayoutExample.java:56:错误:找不到符号
layoutContainer(getContentpane());
^
符号:方法getContentpane()
位置:类FLowLayoutExample
1错误应键入“getContentPane”而不是“getContentPane”。应键入“getContentPane”而不是“getContentPane”