JAVA 24
24 left to right && username and password from user
Q1]
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TextScrolling extends JPanel implements ActionListener {
private static final int PANEL_WIDTH = 400;
private static final int PANEL_HEIGHT = 100;
private static final int TEXT_WIDTH = 200;
private static final int TEXT_HEIGHT = 50;
private static final int SCROLL_DELAY = 50; // Adjust scroll speed here
private int textPosition = PANEL_WIDTH;
private Timer timer;
public TextScrolling() {
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
timer = new Timer(SCROLL_DELAY, this);
timer.start();
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLACK);
g.fillRect(0, 0, PANEL_WIDTH, PANEL_HEIGHT);
g.setColor(Color.WHITE);
Font font = new Font("Arial", Font.BOLD, 24);
g.setFont(font);
g.drawString("Scrolling Text", textPosition, PANEL_HEIGHT / 2 + g.getFontMetrics().getHeight() / 2);
}
@Override
public void actionPerformed(ActionEvent e) {
textPosition--;
if (textPosition + TEXT_WIDTH < 0) {
textPosition = PANEL_WIDTH;
}
repaint();
}
public static void main(String[] args) {
JFrame frame = new JFrame("Text Scrolling");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new TextScrolling());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Q2]
login.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
if (username != null && password != null && username.equals(password)) {
response.sendRedirect("Login.html");
} else {
response.sendRedirect("Error.html");
}
%>
</body>
</html>
Login.html:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Login Successfully</title> </head> <body> <h2>Login Successfully</h2> </body> </html>Error.html:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Login Failed</title> </head> <body> <h2>Login Failed</h2> </body> </html>