Question: Need help writing Java Code. home / study / engineering / computer science / questions and answers / need help writing java code import javax.swing.jframe;

Need help writing Java Code.

Need help writing Java Code. home / study / engineering / computer

home / study / engineering / computer science / questions and answers / need help writing java code import javax.swing.jframe; ...

Your question has been answered

Let us know if you got a helpful answer. Rate this answer

Question: Need help writing Java Code import javax.swing.JF...

Need help writing Java Code

science / questions and answers / need help writing java code import

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JButton;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class ThreadedFillDemo extends JFrame implements ActionListener

{

public static final int WIDTH = 300;

public static final int HEIGHT = 200;

public static final int FILL_WIDTH = 300;

public static final int FILL_HEIGHT = 100;

public static final int CIRCLE_SIZE = 10;

public static final int PAUSE = 100; //milliseconds

private JPanel box;

public static void main(String[] args)

{

ThreadedFillDemo gui = new ThreadedFillDemo( );

gui.setVisible(true);

}

public ThreadedFillDemo( )

{

setSize(WIDTH, HEIGHT);

setTitle("Threaded Fill Demo");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new BorderLayout( ));

box = new JPanel( );

add(box, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel( );

buttonPanel.setLayout(new FlowLayout( ));

JButton startButton = new JButton("Start");

startButton.addActionListener(this);

buttonPanel.add(startButton);

add(buttonPanel, BorderLayout.SOUTH);

}

public void actionPerformed(ActionEvent e)

{

Packer packerThread = new Packer( );

packerThread.start( );

}

private class Packer extends Thread

{

public void run( )

{

Graphics g = box.getGraphics( );

for (int y = 0; y

for (int x = 0; x

{

g.fillOval(x, y, CIRCLE_SIZE, CIRCLE_SIZE);

doNothing(PAUSE);

}

}

public void doNothing(int milliseconds)

{

try

{

Thread.sleep(milliseconds);

}

catch(InterruptedException e)

{

System.out.println("Unexpected interrupt");

System.exit(0);

}

}

} //End Packer inner class

}

Modify the GUI in Display 19.2 (ThreadedFillDemo.Java, you can find the code in the assignment folder) so that the circles are alternately red, white and blue, and so that they fill the area from bottom to up instead of top to bottom

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!