Group B
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
*/ import java.awt.*; import java.awt.event.*; class ButtonDemo extends Frame implements ActionListener { Button b1,b2,b3; Label l; ButtonDemo() { setLayout(new FlowLayout()); b1=new Button("RED"); b2=new Button("BLUE"); b3=new Button("GREEN"); l=new Label(""); add(b1); add(b2); add(b3); add(l); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { l.setText("RED"); } else if(e.getSource()==b2) { l.setText("BLUE"); } else if(e.getSource()==b3) { l.setText("GREEN"); } } public static void main(String args[]) { ButtonDemo b=new ButtonDemo(); b.setSize(400,400); b.setVisible(true); } } |
Q.no 3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import java.sql.*; public class Marvel { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Marvel", "root", "root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from Movie where genre='action'"); while (rs.next()) System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getString(3)); con.close(); } catch (Exception e) { System.out.println(e); } } } </code> |
Q.no 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="MouseListenerDemo" width=300 height=100> </applet> */ public class MouseListenerDemo extends Applet implements MouseListener { String msg=""; int mouseX=0,mouseY=0; public void init() { addMouseListener(this); } public void mouseClicked(MouseEvent me) { mouseX=0; mouseY=10; msg="Mouse Clicked"; repaint(); } public void mouseEntered(MouseEvent me) { mouseX=0; mouseY=10; msg="Mouse Entered"; repaint(); } public void mouseExited(MouseEvent me) { mouseX=0; mouseY=10; msg="Mouse Exited"; repaint(); } public void mousePressed(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); msg="Down"; repaint(); } public void mouseReleased(MouseEvent me) { mouseX=me.getX(); mouseY=me.getY(); msg="Up"; repaint(); } public void paint(Graphics g) { g.drawString(msg,mouseX,mouseY); } } |
How is servlet depoyed ? Explain.
Servlets are usually deployed in web containers, such as Apache Tomcat. The web container provides an environment for servlets to run in, managing threading, connection pooling, security, and other services. When a web server receives a request for a servlet, it passes the request to the corresponding servlet container. The container then loads the servlet (if it is not already loaded) and executes it. The servlet accesses the request parameters and headers, and generates a response. The response is passed back to the web server, which in turn passes it on to the client.
Q.no 8
JTable is a Swing component that displays a tabular view of data. It is used to display and edit data in a tabular format. It is a powerful component that allows you to quickly and easily create tables with data from a variety of sources.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public class JTableDemo extends JFrame { public JTableDemo() { super("JTable Demo"); setSize(400, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); String[] columnNames = { "Name", "Age", "Sex" }; Object[][] data = { { "John", new Integer(25), "Male" }, { "Mary", new Integer(30), "Female" }, { "Joe", new Integer(40), "Male" }, { "Susan", new Integer(35), "Female" } }; JTable table = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); setVisible(true); } public static void main(String[] args) { new JTableDemo(); } |