Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rewrite the java netbeans program below into JavaFX netbeans. import java.awt.*; import javax.swing.*; public class L4_bresenham { public static void main(String[] args) { System.out.print(Enter x1,

Rewrite the java netbeans program below into JavaFX netbeans.

import java.awt.*; import javax.swing.*; public class L4_bresenham {

public static void main(String[] args) { System.out.print("Enter x1, y1, x2, y2, respectively(from zero to 600): "); java.util.Scanner input = new java.util.Scanner(System.in); Bresenham line = new Bresenham(input.nextInt(), input.nextInt(), input.nextInt(), input.nextInt()); JFrame frame = new JFrame("Bresenham Line"); frame.setSize(800, 800); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); line.setPreferredSize(new Dimension(600,600)); frame.add(line); frame.pack(); frame.setVisible(true); }//end main }//end class

import java.awt.Graphics; import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; import javax.swing.JApplet;

public class Bresenham extends JApplet{ BufferedImage image = new BufferedImage(600, 600, BufferedImage.TYPE_INT_ARGB); WritableRaster raster = image.getRaster(); int x1, x2, y1, y2; Bresenham(int x1, int y1, int x2, int y2){ this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; init(); } public void init() { setSize(600, 600); repaint(); } float updateP(float p, float dy, float dx){ return p < 0? p + 2*dy : p + 2*(dy-dx); } public void paint(Graphics g) {float dx, dy; int color[] = {255, 0, 0, 255}; dx = Math.abs( x2 - x1); dy = Math.abs(y2 - y1); float slope = dy / dx; boolean swapped = false; // determine if a swap is needed if(slope > 1){ float temp = x1; x1 = y1; y1 = (int)temp; temp = x2; x2 = y2; y2 = (int)temp; temp = dx; dx = dy; dy = temp; swapped = true; } float p = 2*dy - dx; raster.setPixel(x1, y1, color); for(int k = 1; k <= dx; k++){ if(swapped) System.out.println("x: " + y1 + " y: " + x1); else System.out.println("x: " + x1 + " y: " + y1); if (p<0){ if(x1 < x2) x1++; else x1--; } else{ if(y1 < y2) y1++; else y1--; if(x1 < x2) x1++; else x1--; } p = updateP(p, dy, dx); if(slope>1) raster.setPixel(y1, x1, color); else raster.setPixel(x1, y1, color); } if(swapped) System.out.println("x: " + y1 + " y: " + x1); else System.out.println("x: " + x1 + " y: " + y1); g.drawImage(image, 0, 0, null); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

How well do you work in teams?

Answered: 1 week ago

Question

socialist egalitarianism which resulted in wage levelling;

Answered: 1 week ago

Question

soyuznye (all-Union, controlling enterprises directly from Moscow);

Answered: 1 week ago