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();
}
}
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();
}
}
PLEASE HELP I'M GETTING A "cannot find symbol - variable CENTER" ERROR: import javax.swing.*; import java.awt.*;...
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 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 { 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.*; 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");...
package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{ JButton button1; JLabel label1; public int minutes=3;//initial time public int time=minutes*60;//total amount of time in seconds only public int seconds=time%60; public String defaulttimeset="0"+Integer.toString(minutes)+":0"+Integer.toString(seconds); public static void main(String[] args) { Timing move=new Timing(); move.go(); } public void go(){ JFrame frame=new JFrame(); frame.setBounds(50,50,400,400); JPanel panel2=new JPanel(); button1=new JButton("Start Time"); panel2.add(button1); button1.setBounds(30,50,150,170); frame.getContentPane().add(button1);...
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 {
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 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 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 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....