Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Add a pause/resume button to the Welcome Students that will stop/resume the movement of the text. code>>>>>> import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*;
Add a pause/resume button to the Welcome Students that will stop/resume the movement of the text.
code>>>>>>
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class WelcomeStudents extends JFrame { String welcome = "Welcome"; String students = "Students"; JButton b=new JButton("pause/resume"); int y_welcome = 50; int y_students = 150; int x_welcome = 10; int x_students= 10; int welcome_inc = 1; int students_inc = 1; public WelcomeStudents(){ setSize(250,100); setDefaultCloseOperation(EXIT_ON_CLOSE); add(b,BorderLayout.SOUTH); setVisible(true); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(e.getSource()==b){ } }}); } public void paint(Graphics g){ super.paint(g); g.setFont(new Font("Times New Roman",Font.BOLD,20)); g.drawString(welcome , y_welcome , x_welcome); g.drawString(students , y_students , x_students); x_welcome = x_welcome + welcome_inc; x_students = students_inc + x_students; if(x_welcome == getWidth()-60 || x_welcome == 0) welcome_inc = welcome_inc* (-1); if(x_students == getWidth()-77 || x_students == 0) x_students = x_students * (-1); try{ Thread.sleep(200); } catch(InterruptedException r){ System.out.println(r.getMessage()); } repaint(); } public static void main(String[]args){ new WelcomeStudents(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started