Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将getContentpane与FlowLayout一起使用以应用对布局的更改,但不起作用。为什么?_Java_Swing_Compiler Errors_Awt_Cannot Find Symbol - Fatal编程技术网

Java 将getContentpane与FlowLayout一起使用以应用对布局的更改,但不起作用。为什么?

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

大家好,我正在尝试用actionListener制作3个按钮(左、中、右),因此当有人单击其中一个按钮时,框架的FlowLayout对齐方式会发生变化,但当我尝试使用getContentpane()方法时,它无法正常工作!这是我的密码:

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”