package javaapplication154;
import javax.swing.*;
import java.awt.*;
import java.awt.Color; //no error but not needed to write since you
have included java.awt.* which gets all classes and interfaces in
awt package
public class JGraphicsPanel extends JPanel
{
public JGraphicsPanel(Color color)
{
this.setBackground(color);
}
public void paint(Graphics g) //g is reference to Graphics
class
{
super.paint(g); //passing g as parameter to paint()
g.setColor(new Color(0,0,0)); //passing Color object as argument to
setColor() method
//Calling the below methods of Graphics class using reference
'g'
g.fillOval(10,5,40,40);
g.fillOval(60,5,40,40);
}
}
package javaapplication154;
import java.awt.Color;
import javax.swing.JFrame;
public class JavaApplication154
{
public static void main(String[] args)
{
JFrame frame=new JFrame("Using colors");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JGraphicsPanel GraphicsPanel=new JGraphicsPanel(Color.RED);
frame.add(GraphicsPanel); //mandatory to add panel to frame
frame.setSize(400,180);
frame.setVisible(true); //sets frame visibility to true
}
}
Output
2. Find the error(s), correct it, and write output. Point 5 package javaapplication154 import javax.swing.* import...
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() {...
Ex: In relation to image painting in frame, the following code is the use of getImage() in toolkit. Modify the image() through ImageIcon and imageIO.read() of javax into a converted form using imageIO.read(). import java.awt.*; import javax.swing.*; public class FrameImage extends JPanel{ public void paint(Graphics g) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image = toolkit.getImage("image/grapes.gif"); g.drawImage(image, 60, 40, this); } public static void main(String[] args) { JFrame frame = new JFrame(); FrameImage pannell = new FrameImage(); frame.add(pannell); frame.setTitle("image paint"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);...
The program given here will draw the Olympic logo. Modify the program as the following: 1.Change the class name to Test1OlympicYourFirstNameYourLastName 2.Change the OlympicRingPanel class name to OlympicRingPanelYourfirstNameYourLastName 3.Modify the program so that the first ring will be filled with random color with a random alpha value. I have shown 3 sample output here for your references. 4.Modify the paintComponent so your name will be displayed under the Olympic rings.The color of your name should be random color as well....
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...
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); ...
tart from the following code, and add Action Listener to make it functional to do the temperature conversion in the direction of the arrow that is clicked. . (Need about 10 lines) Note: import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class temperatureConverter extends JFrame { public static void main(String[] args) { JFrame frame = new temperatureConverter(); frame.setTitle("Temp"); frame.setSize(200, 100); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public temperatureConverter() { JLabel lblC = new...
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));...
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");...
Program #2 Write a program to simulate showing an NBA Team on a Basketball court Here is an example of the screenshot when running the program: Tony Parker T. Splitter T. Duncan M. Gineb Player Kame: M Ginobil Player Age 2 Add A Player Ce An example of the JFrame subclass with main method is as follows import java.awt. import java.awt.event." import javax.swing. public class NBA Playoff extends JFrame private JTextField txtName: private JTextField txtAge: private NBATeam spurs private NBAcourtPanel...
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();...