Question

PLEASE HELP I'M GETTING A "cannot find symbol - variable CENTER" ERROR: import javax.swing.*; import java.awt.*;...

PLEASE HELP I'M GETTING A "cannot find symbol - variable CENTER" ERROR:

import javax.swing.*;
import java.awt.*;

/**
* Write a description of class FlowLayout here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class FlowLayout
{
// instance variables - replace the example below with your own
JButton button1,button2,button3;
JFrame jFrame;
  

/**
* Constructor for objects of class FlowLayout
*/
FlowLayout()
{
// initialise instance variables
jFrame= new JFrame("FlowLayout Example");
jFrame.setLayout(new FlowLayout(FlowLayout.CENTER));
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button1 = new JButton("Left");
button2 = new JButton("Center");
button3 = new JButton("Right");
jFrame.add(button1);
jFrame.add(button2);
jFrame.add(button3);
jFrame.setSize(250,80);
jFrame.setVisible(true);
}

/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public static void main(String[] args)
{
new FlowLayout();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Actually issue is with class name. FlowLayout is a class of java.awt package. you are trying to make a class with same name and still using the java.awt class. which is giving the issue.

So simple solution is to rename the class. Below is the correct code. Please include your imports.

/**

* Write a description of class FlowLayout here.

*

* @author (your name)

* @version (a version number or a date)

*/

public class MyFlowLayout {

// instance variables - replace the example below with your own

JButton button1, button2, button3;

JFrame jFrame;

/**

* Constructor for objects of class FlowLayout

*/

MyFlowLayout() {

// initialise instance variables

jFrame = new JFrame("FlowLayout Example");

jFrame.setLayout(new FlowLayout(FlowLayout.CENTER));

jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

button1 = new JButton("Left");

button2 = new JButton("Center");

button3 = new JButton("Right");

jFrame.add(button1);

jFrame.add(button2);

jFrame.add(button3);

jFrame.setSize(250, 80);

jFrame.setVisible(true);

}

/**

* An example of a method - replace this comment with your own

*

* @param y

* a sample parameter for a method

* @return the sum of x and y

*/

public static void main(String[] args) {

new MyFlowLayout();

}

}

Add a comment
Know the answer?
Add Answer to:
PLEASE HELP I'M GETTING A "cannot find symbol - variable CENTER" ERROR: import javax.swing.*; import java.awt.*;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • 2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import...

    2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import java.awt. import java.awt.Color publie class JGraphicsPanel extends JPanel f public JGraphiesPanel(Color color) f this.setBackground(color); public void paint(Graphies super.paint0; setColor(0,0,0); filloval(10, 5, 40, 40); fillOval(60, 5, 40, 40); package javaapplication154; import java.awt.Color; import javax.swing.JFrame; public class JavaApplication154 public static void main(Stringl) args) [ JFrame frame- new JFrame( "Using colors"); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); JGraphiesPanel GraphiesPanel-new JGraphiesPanel(Color.RED); frame.setSize( 400, 180); frame.setVisible );

  • There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame...

    There 2 parts to complete: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class Q4 extends JFrame { private int xPos, yPos; public Q4() { JPanel drawPanel = new JPanel() { @Override public void paintComponent(Graphics g) { super.paintComponent(g); // paint parent's background //complete this: } }; drawPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { //complete this :- set the xPos, yPos }    }); setContentPane(drawPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Mouse-Click Demo"); setSize(400, 250); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {...

  • Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*;...

    Can you please fix the error. package com.IST240Apps; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import java.net.*; public class LinkRotator extends JFrame implements Runnable, ActionListener { String[] pageTitle = new String[5]; URI[] pageLink = new URI[5]; int current = 0; Thread runner; JLabel siteLabel = new Jlabel(); public LinkRotator() { setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE); setSize(300, 100); FlowLayout flo = new Flowlayout(); setLayout(flo); add(siteLabel); pageTitle = new String[] { "Oracle Java Site", "Server Side", "JavaWorld", "Google", "Yahoo", "Penn State" }; pageLink[0] = getUR1("http://www.oracle.com/technetwork/java");...

  • GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public...

    GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public class DrawingFrame extends JFrame {    JButton loadButton, saveButton, drawButton;    JComboBox colorList, shapesList;    JTextField parametersTextField;       DrawingFrame() {        super("Drawing Application");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JToolBar toolbar = new JToolBar();        toolbar.setRollover(true);        toolbar.add(loadButton=new JButton("Load"));        toolbar.add(saveButton=new JButton("Save"));        toolbar.addSeparator();        toolbar.add(drawButton=new JButton("Draw"));               toolbar.addSeparator();        toolbar.addSeparator();        toolbar.add(new...

  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

  • import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow...

    import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT