Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using JavaFX Il. Step 1: This part is to test if you have understood the lab ass

ID: 3856433 • Letter: U

Question

Using JavaFX

Il. Step 1: This part is to test if you have understood the lab assignments that we have done in the class. Write a program to produce the following output. (Use any two colors you like.) 1) 2) Switch Note: At this step you do not need to implement the Switch Button Handler. Just mange to have Circle, Ellipse, and the Button displayed as shown. IlI Step 2: Implement the Switch Button H Implement the Switch Button Handler so that whenever the user clicks the Switch button, the Circle and Ellipse will change place. For example, if the user clicks the Switch button on the above output, the output will become: Step 2: Switch

Explanation / Answer

Step: 1

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.stage.Stage;  
import javafx.scene.shape.Circle;  
          
public class CircleExample extends Application {  
   @Override  
   public void start(Stage stage) {  
      //Drawing a Circle  
      Circle circle = new Circle();  
          
      //Setting the properties of the circle  
      circle.setCenterX(300.0f);  
      circle.setCenterY(135.0f);  
      circle.setRadius(100.0f);  
          
      //Creating a Group object   
      Group root = new Group(circle);  
          
      //Creating a scene object  
      Scene scene = new Scene(root, 600, 300);   
      //Setting title to the Stage  
      stage.setTitle("Drawing a Circle");  
          
      //Adding scene to the stage  
      stage.setScene(scene);  
          
      //Displaying the contents of the stage  
      stage.show();
   }  
   public static void main(String args[]){  
      launch(args);  
   }  
}

iv Step3:

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;

public class ComplexShape extends Application {
@Override
public void start(Stage stage) {
//Creating a Path
Path path = new Path();

MoveTo moveTo = new MoveTo(108, 71);

LineTo line1 = new LineTo(321, 161);

LineTo line2 = new LineTo(126,232);   


LineTo line3 = new LineTo(232,52);

LineTo line4 = new LineTo(269, 250);   

LineTo line5 = new LineTo(108, 71);

path.getElements().add(moveTo);
path.getElements().addAll(line1, line2, line3, line4, line5);


Group root = new Group(path);

Scene scene = new Scene(root, 600, 300);
  

stage.setTitle("Drawing an arc through a path");

stage.setScene(scene);

stage.show();   
}
public static void main(String args[]){
launch(args);
}
}   

Since I am working as C# developer So , C# code is similar to Java, So no need to worry, Just have a look

Using C# We can Achieve All Steps

(This is the C# Windows Appplication):

Add Form1.cs[Design]

Go in Code View : Use Code Like

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace WinForms_Drawing_cs

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private System.Drawing.Graphics g;

private System.Drawing.Pen pen1 = new System.Drawing.Pen(Color.Blue, 2F);

private void butLine_Click(object sender, EventArgs e)

{

g = PictureBox1.CreateGraphics();

g.DrawLine(pen1, 250, 50, 400, 200);

}

private void butEllipse_Click(object sender, EventArgs e)

{

g = PictureBox1.CreateGraphics();

g.DrawEllipse(pen1, 50, 50, 100, 150);

}

private void butRectangle_Click(object sender, EventArgs e)

{

g = PictureBox1.CreateGraphics();

g.DrawRectangle(pen1, 30, 30, 50, 60);

}

private void butArc_Click(object sender, EventArgs e)

{

g = PictureBox1.CreateGraphics();

g.DrawArc(pen1, 150, 100, 150, 200, 150, 160);

}

private void butPie_Click(object sender, EventArgs e)

{

g = PictureBox1.CreateGraphics();

g.DrawPie(pen1, 50, 50, 150, 150, 0, 170);

}

private void butPolygon_Click(object sender, EventArgs e)

{

System.Drawing.Point[] p = new System.Drawing.Point[6];

p[0].X = 0;

p[0].Y = 0;

p[1].X = 53;

p[1].Y = 111;

p[2].X = 114;

p[2].Y = 86;

p[3].X = 34;

p[3].Y = 34;

p[4].X = 165;

p[4].Y = 7;

g = PictureBox1.CreateGraphics();

g.DrawPolygon(pen1, p);

}

private void butBezier_Click(object sender, EventArgs e)

{

g = PictureBox1.CreateGraphics();

g.DrawBezier(pen1, 100, 200, 240, 250, 100, 200, 150, 30);

}

private void butClear_Click(object sender, EventArgs e)

{

PictureBox1.Refresh();

}

}

}

In Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WinForms_Drawing_cs
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

Note: If you have any query , Please send any time..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote