diff --git a/Chatting_Application/Client10.java b/Chatting_Application/Client10.java new file mode 100644 index 0000000..974bd44 --- /dev/null +++ b/Chatting_Application/Client10.java @@ -0,0 +1,236 @@ +package Chatting_Application; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.*; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class Client10 extends JFrame implements ActionListener // ActionListener from "awt.event" +{ + JTextField text; // Globally declare text field(going to be used in ActionListener) + static JPanel a1; + static Box vertical = Box.createVerticalBox(); // Vertical box for messages + static DataOutputStream dout; + static JFrame t = new JFrame(); + + public Client10() { + //new Server(); + t.setLayout(null); + + JPanel p1 = new JPanel(); //JPanel = if we want to insert anything on frame + p1.setBackground(new Color(7, 94, 84)); + p1.setBounds(0, 0, 400, 70); + p1.setLayout(null); + t.add(p1); + + +//********************************************* BACK BUTTON *********************************************** + + + ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/3.png")); + Image i2 = i1.getImage().getScaledInstance(25, 25, Image.SCALE_DEFAULT); //Image class in "awt" + + ImageIcon i3 = new ImageIcon(i2); + + JLabel add_img = new JLabel(i3); + add_img.setBounds(5, 20, 25, 25); + p1.add(add_img); + + add_img.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) { + t.setVisible(false); + } + } + ); + +//********************************************* PROFILE IMAGE *********************************************** + + ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("icons/client15.png")); + Image i5 = i4.getImage().getScaledInstance(50, 50, Image.SCALE_DEFAULT); + ImageIcon i6 = new ImageIcon(i5); + JLabel profile = new JLabel(i6); + profile.setBounds(40, 10, 50, 50); + p1.add(profile); + + +//********************************************* VIDEO IMAGE *********************************************** + + + ImageIcon i7 = new ImageIcon(ClassLoader.getSystemResource("icons/video.png")); + Image i8 = i7.getImage().getScaledInstance(30, 30, Image.SCALE_DEFAULT); + ImageIcon i9 = new ImageIcon(i8); + JLabel video = new JLabel(i9); + video.setBounds(250, 20, 30, 30); + p1.add(video); + + +//********************************************* PHONE IMAGE *********************************************** + + + ImageIcon i10 = new ImageIcon(ClassLoader.getSystemResource("icons/phone.png")); + Image i11 = i10.getImage().getScaledInstance(35, 30, Image.SCALE_DEFAULT); + ImageIcon i12 = new ImageIcon(i11); + JLabel phone = new JLabel(i12); + phone.setBounds(300, 20, 35, 30); + p1.add(phone); + + +//********************************************* MORE IMAGE *********************************************** + + + ImageIcon i13 = new ImageIcon(ClassLoader.getSystemResource("icons/3icon.png")); + Image i14 = i13.getImage().getScaledInstance(10, 25, Image.SCALE_DEFAULT); + ImageIcon i15 = new ImageIcon(i14); + JLabel More_op = new JLabel(i15); + More_op.setBounds(350, 20, 10, 25); + p1.add(More_op); + + +//********************************************* NAME OF THE USER *********************************************** + + + JLabel name = new JLabel("Prisha"); + name.setBounds(110, 15, 100, 18); + name.setForeground(Color.white); + name.setFont(new Font("SAN_SERIF", Font.BOLD, 21)); + p1.add(name); + + +//********************************************* STATUS OF THE USER ************************************************* + + + JLabel Status = new JLabel("Active Now"); + Status.setBounds(110, 42, 100, 18); + Status.setForeground(Color.white); + Status.setFont(new Font("SAN_SERIF", Font.BOLD, 14)); + p1.add(Status); + + +//************************************************** TEXT AREA ************************************************* + + + a1 = new JPanel(); + a1.setBounds(5, 75, 390, 520); + t.add(a1); + + +//************************************************** USER CHAT ************************************************* + + + text = new JTextField(); + text.setBounds(2, 599, 280, 40); + text.setFont(new Font("SAN_SERIF", Font.PLAIN, 16)); + t.add(text); + + +//********************************************* SEND BUTTON ************************************************* + + JButton send = new JButton("Send"); + send.setBounds(285, 599, 110, 40); + send.setBackground(new Color(7, 94, 84)); + send.setForeground(Color.white); + send.addActionListener(this); // Send button click + send.setFont(new Font("SAN_SERIF", Font.PLAIN, 16)); + t.add(send); + + + t.setSize(400, 650); // setSize() fun in JFrame + t.setLocation(800, 50); // need to change location as default location is top left + t.setUndecorated(true); // remove header (increases size of frame) + t.getContentPane().setBackground(Color.white); // Color class is under "awt" + t.setVisible(true); // Default visibility is false + } + + public void actionPerformed(ActionEvent ae) { + try { + String out = text.getText(); + + JPanel p2 = formatLabel(out); + + a1.setLayout(new BorderLayout()); + + JPanel right = new JPanel(new BorderLayout()); + right.add(p2, BorderLayout.LINE_END); + vertical.add(right); // Add message in vertical box(For multiple messages) + vertical.add(Box.createVerticalStrut(15)); + + a1.add(vertical, BorderLayout.PAGE_START); // Append all this on text area + + dout.writeUTF(out); + + text.setText(""); // To delete the text from chat area after it is sent + + + t.repaint(); // All three fun used to reload the frame + t.invalidate(); // so that sent texts would be seen + t.validate(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static JPanel formatLabel(String out) { + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + + JLabel output = new JLabel(out); + output.setFont(new Font("Tahoma", Font.PLAIN, 16)); //"Tahoma" = Font name + // set font of text which user will send + output.setBackground(new Color(37, 211, 102)); + output.setOpaque(true); // For background color to be visible + + output.setBorder(new EmptyBorder(15, 15, 15, 50)); + panel.add(output); + + +//********************************************************** DATE AND TIME************************************************* + + + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); + + JLabel time = new JLabel(); + time.setText(sdf.format(cal.getTime())); + + panel.add(time); + return panel; + } + + public static void main(String[] args) + { + new Client10(); + + try { + Socket s = new Socket("127.0.0.1", 6001); // "127.0.0.1" = local host + // Socket helps to connect with server class + DataInputStream din = new DataInputStream(s.getInputStream()); // To receive messages + dout = new DataOutputStream(s.getOutputStream()); // To send messages + + while (true) { + a1.setLayout(new BorderLayout()); + + String meg = din.readUTF(); // To read a message + JPanel panel = formatLabel(meg); // Add on frame + + JPanel left = new JPanel(new BorderLayout()); + left.add(panel, BorderLayout.LINE_START); // Received messages on left + + vertical.add(left); + vertical.add(Box.createVerticalStrut(15)); + a1.add(vertical, BorderLayout.PAGE_START); + + t.validate(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } +} +//} diff --git a/Chatting_Application/Server10.java b/Chatting_Application/Server10.java new file mode 100644 index 0000000..3018bce --- /dev/null +++ b/Chatting_Application/Server10.java @@ -0,0 +1,251 @@ +package Chatting_Application; + +import Connection.Client; +import Connection.Server; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.*; +import java.io.DataInputStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.io.*; + +public class Server10 extends JFrame implements ActionListener // ActionListener from "awt.event" +{ + static JTextField text; // Globally declare text field(going to be used in ActionListener) + static JPanel a1; + static Box vertical = Box.createVerticalBox(); // Vertical box for messages + static JFrame t = new JFrame(); + static DataOutputStream dout; + public Server10() + { + t.setLayout(null); + + JPanel p1 = new JPanel(); //JPanel = if we want to insert anything on frame + p1.setBackground(new Color(7,94,84)); + p1.setBounds(0,0,400,70); + p1.setLayout(null); + t.add(p1); + + +//********************************************* BACK BUTTON *********************************************** + + + ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/3.png")); + Image i2 = i1.getImage().getScaledInstance(25,25,Image.SCALE_DEFAULT); //Image class in "awt" + + ImageIcon i3 = new ImageIcon(i2); + + JLabel add_img = new JLabel(i3); + add_img.setBounds(5,20,25,25); + p1.add(add_img); + + add_img.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + t.setVisible(false); + } + } + ); + +//********************************************* PROFILE IMAGE *********************************************** + + + ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("icons/server15.png")); + Image i5 = i4.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT); + ImageIcon i6 = new ImageIcon(i5); + JLabel profile = new JLabel(i6); + profile.setBounds(40,10,50,50); + p1.add(profile); + + +//********************************************* VIDEO IMAGE *********************************************** + + + ImageIcon i7 = new ImageIcon(ClassLoader.getSystemResource("icons/video.png")); + Image i8 = i7.getImage().getScaledInstance(30,30,Image.SCALE_DEFAULT); + ImageIcon i9 = new ImageIcon(i8); + JLabel video = new JLabel(i9); + video.setBounds(250,20,30,30); + p1.add(video); + + +//********************************************* PHONE IMAGE *********************************************** + + + ImageIcon i10 = new ImageIcon(ClassLoader.getSystemResource("icons/phone.png")); + Image i11 = i10.getImage().getScaledInstance(35,30,Image.SCALE_DEFAULT); + ImageIcon i12 = new ImageIcon(i11); + JLabel phone = new JLabel(i12); + phone.setBounds(300,20,35,30); + p1.add(phone); + + +//********************************************* MORE IMAGE *********************************************** + + + ImageIcon i13 = new ImageIcon(ClassLoader.getSystemResource("icons/3icon.png")); + Image i14 = i13.getImage().getScaledInstance(10,25,Image.SCALE_DEFAULT); + ImageIcon i15 = new ImageIcon(i14); + JLabel More_op = new JLabel(i15); + More_op.setBounds(350,20,10,25); + p1.add(More_op); + + +//********************************************* NAME OF THE USER *********************************************** + + + JLabel name = new JLabel("Aagastya"); + name.setBounds(110,15,100,18); + name.setForeground(Color.white); + name.setFont(new Font("SAN_SERIF",Font.BOLD,21)); + p1.add(name); + + +//********************************************* STATUS OF THE USER ************************************************* + + + JLabel Status = new JLabel("Active Now"); + Status.setBounds(110,42,100,18); + Status.setForeground(Color.white); + Status.setFont(new Font("SAN_SERIF",Font.BOLD,14)); + p1.add(Status); + + +//************************************************** TEXT AREA ************************************************* + + + a1 = new JPanel(); + a1.setBounds(5,75,390,520); + t.add(a1); + + +//************************************************** USER CHAT ************************************************* + + + text = new JTextField(); + text.setBounds(2,599,280,40); + text.setFont(new Font("SAN_SERIF",Font.PLAIN,16)); + t.add(text); + + +//***************************************************** SEND BUTTON *************************************************** + + JButton send = new JButton("Send"); + send.setBounds(285,599,110,40); + send.setBackground(new Color(7,94,84)); + send.setForeground(Color.white); + send.addActionListener(this); // Send button click + send.setFont(new Font("SAN_SERIF",Font.PLAIN,16)); + t.add(send); + +//-------------------------------------------------------------------------------------------------------------------------- + + + t.setSize(400,650); // setSize() fun in JFrame + t.setLocation(300,50); // need to change location as default location is top left + t.setUndecorated(true); // remove header (increases size of frame) + t.getContentPane().setBackground(Color.white); // Color class is under "awt" + t.setVisible(true); // Default visibility is false + } + + public void actionPerformed(ActionEvent ae) { + try { + String out = text.getText(); + + JPanel p2 = formatLabel(out); + + a1.setLayout(new BorderLayout()); + + JPanel right = new JPanel(new BorderLayout()); + right.add(p2, BorderLayout.LINE_END); + vertical.add(right); // Add message in vertical box(For multiple messages) + vertical.add(Box.createVerticalStrut(15)); + + a1.add(vertical, BorderLayout.PAGE_START); // Append all this on text area + + + dout.writeUTF(out); + + text.setText(""); // To delete the text from chat area after it is sent + + + t.repaint(); // All three fun used to reload the frame + t.invalidate(); // so that sent texts would be seen + t.validate(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public static JPanel formatLabel(String out) + { + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); + + JLabel output = new JLabel(out); + output.setFont(new Font("Tahoma",Font.PLAIN,16)); //"Tahoma" = Font name + // set font of text which user will send + output.setBackground(new Color(37,211,102)); + output.setOpaque(true); // For background color to be visible + + output.setBorder(new EmptyBorder(15,15,15,50)); + panel.add(output); + + + +//********************************************************** DATE AND TIME************************************************* + + + + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); + + JLabel time = new JLabel(); + time.setText(sdf.format(cal.getTime())); + + panel.add(time); + +//-------------------------------------------------------------------------------------------------------------------------- + + return panel; + } + public static void main(String[] args) + { + new Server10(); + try + { + ServerSocket skt = new ServerSocket(6001); // For real time chatting + + while(true) // condition for infinite chatting + { + Socket s = skt.accept(); + DataInputStream din = new DataInputStream(s.getInputStream()); // To receive messages + dout = new DataOutputStream(s.getOutputStream()); // To send messages + + while(true) + { + String meg = din.readUTF(); // To read a message + JPanel panel = formatLabel(meg); // Add on frame + + JPanel left = new JPanel(new BorderLayout()); + left.add(panel,BorderLayout.LINE_START); // Received messages on left + + vertical.add(left); + t.validate(); + } + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/Chatting_Application/icons/1.png b/Chatting_Application/icons/1.png new file mode 100644 index 0000000..3b8a42f Binary files /dev/null and b/Chatting_Application/icons/1.png differ diff --git a/Chatting_Application/icons/2.png b/Chatting_Application/icons/2.png new file mode 100644 index 0000000..5fbf1d8 Binary files /dev/null and b/Chatting_Application/icons/2.png differ diff --git a/Chatting_Application/icons/3.png b/Chatting_Application/icons/3.png new file mode 100644 index 0000000..f512f88 Binary files /dev/null and b/Chatting_Application/icons/3.png differ diff --git a/Chatting_Application/icons/3icon.png b/Chatting_Application/icons/3icon.png new file mode 100644 index 0000000..decb325 Binary files /dev/null and b/Chatting_Application/icons/3icon.png differ diff --git a/Chatting_Application/icons/Client.png b/Chatting_Application/icons/Client.png new file mode 100644 index 0000000..2d00140 Binary files /dev/null and b/Chatting_Application/icons/Client.png differ diff --git a/Chatting_Application/icons/Server.png b/Chatting_Application/icons/Server.png new file mode 100644 index 0000000..5807f58 Binary files /dev/null and b/Chatting_Application/icons/Server.png differ diff --git a/Chatting_Application/icons/arrow.jpg b/Chatting_Application/icons/arrow.jpg new file mode 100644 index 0000000..191dbe9 Binary files /dev/null and b/Chatting_Application/icons/arrow.jpg differ diff --git a/Chatting_Application/icons/bunty.jpeg b/Chatting_Application/icons/bunty.jpeg new file mode 100644 index 0000000..18dbcfc Binary files /dev/null and b/Chatting_Application/icons/bunty.jpeg differ diff --git a/Chatting_Application/icons/client15.png b/Chatting_Application/icons/client15.png new file mode 100644 index 0000000..d4b98c6 Binary files /dev/null and b/Chatting_Application/icons/client15.png differ diff --git a/Chatting_Application/icons/gaitonde.jpeg b/Chatting_Application/icons/gaitonde.jpeg new file mode 100644 index 0000000..139d89a Binary files /dev/null and b/Chatting_Application/icons/gaitonde.jpeg differ diff --git a/Chatting_Application/icons/logo.png b/Chatting_Application/icons/logo.png new file mode 100644 index 0000000..70e4b1e Binary files /dev/null and b/Chatting_Application/icons/logo.png differ diff --git a/Chatting_Application/icons/mirzapur.png b/Chatting_Application/icons/mirzapur.png new file mode 100644 index 0000000..327eeb8 Binary files /dev/null and b/Chatting_Application/icons/mirzapur.png differ diff --git a/Chatting_Application/icons/phone.png b/Chatting_Application/icons/phone.png new file mode 100644 index 0000000..c81fabb Binary files /dev/null and b/Chatting_Application/icons/phone.png differ diff --git a/Chatting_Application/icons/server15.png b/Chatting_Application/icons/server15.png new file mode 100644 index 0000000..abb1733 Binary files /dev/null and b/Chatting_Application/icons/server15.png differ diff --git a/Chatting_Application/icons/video.png b/Chatting_Application/icons/video.png new file mode 100644 index 0000000..d47d74a Binary files /dev/null and b/Chatting_Application/icons/video.png differ diff --git a/Connection/Client.java b/Connection/Client.java new file mode 100644 index 0000000..dfbdcc5 --- /dev/null +++ b/Connection/Client.java @@ -0,0 +1,248 @@ +package Connection; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class Client extends JFrame implements ActionListener // ActionListener from "awt.event" +{ + JTextField text; // Globally declare text field(going to be used in ActionListener) + static JPanel a1; + static Box vertical = Box.createVerticalBox(); // Vertical box for messages + static DataOutputStream dout; + static JFrame t = new JFrame(); + public Client() + { + //new Server(); + t.setLayout(null); + + JPanel p1 = new JPanel(); //JPanel = if we want to insert anything on frame + p1.setBackground(new Color(7,94,84)); + p1.setBounds(0,0,400,70); + p1.setLayout(null); + t.add(p1); + + +//********************************************* BACK BUTTON *********************************************** + + + ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/3.png")); + Image i2 = i1.getImage().getScaledInstance(25,25,Image.SCALE_DEFAULT); //Image class in "awt" + + ImageIcon i3 = new ImageIcon(i2); + + JLabel add_img = new JLabel(i3); + add_img.setBounds(5,20,25,25); + p1.add(add_img); + + add_img.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + t.setVisible(false); + } + } + ); + +//********************************************* PROFILE IMAGE *********************************************** + + ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("icons/client15.png")); + Image i5 = i4.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT); + ImageIcon i6 = new ImageIcon(i5); + JLabel profile = new JLabel(i6); + profile.setBounds(40,10,50,50); + p1.add(profile); + + +//********************************************* VIDEO IMAGE *********************************************** + + + ImageIcon i7 = new ImageIcon(ClassLoader.getSystemResource("icons/video.png")); + Image i8 = i7.getImage().getScaledInstance(30,30,Image.SCALE_DEFAULT); + ImageIcon i9 = new ImageIcon(i8); + JLabel video = new JLabel(i9); + video.setBounds(250,20,30,30); + p1.add(video); + + +//********************************************* PHONE IMAGE *********************************************** + + + ImageIcon i10 = new ImageIcon(ClassLoader.getSystemResource("icons/phone.png")); + Image i11 = i10.getImage().getScaledInstance(35,30,Image.SCALE_DEFAULT); + ImageIcon i12 = new ImageIcon(i11); + JLabel phone = new JLabel(i12); + phone.setBounds(300,20,35,30); + p1.add(phone); + + +//********************************************* MORE IMAGE *********************************************** + + + ImageIcon i13 = new ImageIcon(ClassLoader.getSystemResource("icons/3icon.png")); + Image i14 = i13.getImage().getScaledInstance(10,25,Image.SCALE_DEFAULT); + ImageIcon i15 = new ImageIcon(i14); + JLabel More_op = new JLabel(i15); + More_op.setBounds(350,20,10,25); + p1.add(More_op); + + +//********************************************* NAME OF THE USER *********************************************** + + + JLabel name = new JLabel("Prisha"); + name.setBounds(110,15,100,18); + name.setForeground(Color.white); + name.setFont(new Font("SAN_SERIF",Font.BOLD,21)); + p1.add(name); + + +//********************************************* STATUS OF THE USER ************************************************* + + + JLabel Status = new JLabel("Active Now"); + Status.setBounds(110,42,100,18); + Status.setForeground(Color.white); + Status.setFont(new Font("SAN_SERIF",Font.BOLD,14)); + p1.add(Status); + + +//************************************************** TEXT AREA ************************************************* + + + a1 = new JPanel(); + a1.setBounds(5,75,390,520); + t.add(a1); + + +//************************************************** USER CHAT ************************************************* + + + text = new JTextField(); + text.setBounds(2,599,280,40); + text.setFont(new Font("SAN_SERIF",Font.PLAIN,16)); + t.add(text); + + +//********************************************* SEND BUTTON ************************************************* + + JButton send = new JButton("Send"); + send.setBounds(285,599,110,40); + send.setBackground(new Color(7,94,84)); + send.setForeground(Color.white); + send.addActionListener(this); // Send button click + send.setFont(new Font("SAN_SERIF",Font.PLAIN,16)); + t.add(send); + + + + t.setSize(400,650); // setSize() fun in JFrame + t.setLocation(800,50); // need to change location as default location is top left + t.setUndecorated(true); // remove header (increases size of frame) + t.getContentPane().setBackground(Color.white); // Color class is under "awt" + t.setVisible(true); // Default visibility is false + } + + public void actionPerformed(ActionEvent ae) { + try { + String out = text.getText(); + + JPanel p2 = formatLabel(out); + + a1.setLayout(new BorderLayout()); + + JPanel right = new JPanel(new BorderLayout()); + right.add(p2, BorderLayout.LINE_END); + vertical.add(right); // Add message in vertical box(For multiple messages) + vertical.add(Box.createVerticalStrut(15)); + + a1.add(vertical, BorderLayout.PAGE_START); // Append all this on text area + + dout.writeUTF(out); + + text.setText(""); // To delete the text from chat area after it is sent + + + t.repaint(); // All three fun used to reload the frame + t.invalidate(); // so that sent texts would be seen + t.validate(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static JPanel formatLabel(String out) + { + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); + + JLabel output = new JLabel(out); + output.setFont(new Font("Tahoma",Font.PLAIN,16)); //"Tahoma" = Font name + // set font of text which user will send + output.setBackground(new Color(37,211,102)); + output.setOpaque(true); // For background color to be visible + + output.setBorder(new EmptyBorder(15,15,15,50)); + panel.add(output); + + + +//********************************************************** DATE AND TIME************************************************* + + + + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); + + JLabel time = new JLabel(); + time.setText(sdf.format(cal.getTime())); + + panel.add(time); + return panel; + + } + public static void main(String[] args) + { + new Client().setVisible(true); + + try + { + Socket s = new Socket("127.0.0.1",6001); // "127.0.0.1" = local host + // Socket helps to connect with server class + DataInputStream din = new DataInputStream(s.getInputStream()); // To receive messages + dout = new DataOutputStream(s.getOutputStream()); // To send messages + + while(true) + { + a1.setLayout(new BorderLayout()); + + String meg = din.readUTF(); // To read a message + JPanel panel = formatLabel(meg); // Add on frame + + JPanel left = new JPanel(new BorderLayout()); + left.add(panel,BorderLayout.LINE_START); // Received messages on left + + vertical.add(left); + vertical.add(Box.createVerticalStrut(15)); + a1.add(vertical,BorderLayout.PAGE_START); + + t.validate(); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/Connection/First_Page/Alarm.png b/Connection/First_Page/Alarm.png new file mode 100644 index 0000000..557f30b Binary files /dev/null and b/Connection/First_Page/Alarm.png differ diff --git a/Connection/First_Page/Chat.png b/Connection/First_Page/Chat.png new file mode 100644 index 0000000..39aad30 Binary files /dev/null and b/Connection/First_Page/Chat.png differ diff --git a/Connection/First_Page/Contact.png b/Connection/First_Page/Contact.png new file mode 100644 index 0000000..101613d Binary files /dev/null and b/Connection/First_Page/Contact.png differ diff --git a/Connection/First_Page/Music.png b/Connection/First_Page/Music.png new file mode 100644 index 0000000..439816e Binary files /dev/null and b/Connection/First_Page/Music.png differ diff --git a/Connection/First_Page/Whatsup.png b/Connection/First_Page/Whatsup.png new file mode 100644 index 0000000..dea8a38 Binary files /dev/null and b/Connection/First_Page/Whatsup.png differ diff --git a/Connection/First_Page/alarm1.png b/Connection/First_Page/alarm1.png new file mode 100644 index 0000000..7acf6f8 Binary files /dev/null and b/Connection/First_Page/alarm1.png differ diff --git a/Connection/First_Page/desktop.ini b/Connection/First_Page/desktop.ini new file mode 100644 index 0000000..ebdee35 --- /dev/null +++ b/Connection/First_Page/desktop.ini @@ -0,0 +1,2 @@ +[LocalizedFileNames] +icons8-alarm-clock-100.png=@icons8-alarm-clock-100,0 diff --git a/Connection/First_Page/radio.png b/Connection/First_Page/radio.png new file mode 100644 index 0000000..822ee70 Binary files /dev/null and b/Connection/First_Page/radio.png differ diff --git a/Connection/First_Page/sirens.png b/Connection/First_Page/sirens.png new file mode 100644 index 0000000..393c774 Binary files /dev/null and b/Connection/First_Page/sirens.png differ diff --git a/Connection/Server.java b/Connection/Server.java new file mode 100644 index 0000000..82e2de2 --- /dev/null +++ b/Connection/Server.java @@ -0,0 +1,260 @@ +package Connection; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.net.ServerSocket; +import java.net.Socket; +import java.text.SimpleDateFormat; +import java.util.Calendar; + +public class Server extends JFrame implements ActionListener // ActionListener from "awt.event" +{ + static JTextField text; // Globally declare text field(going to be used in ActionListener) + static JPanel a1; + static Box vertical = Box.createVerticalBox(); // Vertical box for messages + static JFrame t = new JFrame(); + static DataOutputStream dout; + public Server() + { + + t.setLayout(null); + + JPanel p1 = new JPanel(); //JPanel = if we want to insert anything on frame + p1.setBackground(new Color(7,94,84)); + p1.setBounds(0,0,400,70); + p1.setLayout(null); + t.add(p1); + + +//********************************************* BACK BUTTON *********************************************** + + + ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("icons/3.png")); + Image i2 = i1.getImage().getScaledInstance(25,25,Image.SCALE_DEFAULT); //Image class in "awt" + + ImageIcon i3 = new ImageIcon(i2); + + JLabel add_img = new JLabel(i3); + add_img.setBounds(5,20,25,25); + p1.add(add_img); + + add_img.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + t.setVisible(false); + } + } + ); + +//********************************************* PROFILE IMAGE *********************************************** + + + ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("icons/server15.png")); + Image i5 = i4.getImage().getScaledInstance(50,50,Image.SCALE_DEFAULT); + ImageIcon i6 = new ImageIcon(i5); + JLabel profile = new JLabel(i6); + profile.setBounds(40,10,50,50); + p1.add(profile); + + +//********************************************* VIDEO IMAGE *********************************************** + + + ImageIcon i7 = new ImageIcon(ClassLoader.getSystemResource("icons/video.png")); + Image i8 = i7.getImage().getScaledInstance(30,30,Image.SCALE_DEFAULT); + ImageIcon i9 = new ImageIcon(i8); + JLabel video = new JLabel(i9); + video.setBounds(250,20,30,30); + p1.add(video); + + +//********************************************* PHONE IMAGE *********************************************** + + + ImageIcon i10 = new ImageIcon(ClassLoader.getSystemResource("icons/phone.png")); + Image i11 = i10.getImage().getScaledInstance(35,30,Image.SCALE_DEFAULT); + ImageIcon i12 = new ImageIcon(i11); + JLabel phone = new JLabel(i12); + phone.setBounds(300,20,35,30); + p1.add(phone); + + +//********************************************* MORE IMAGE *********************************************** + + + ImageIcon i13 = new ImageIcon(ClassLoader.getSystemResource("icons/3icon.png")); + Image i14 = i13.getImage().getScaledInstance(10,25,Image.SCALE_DEFAULT); + ImageIcon i15 = new ImageIcon(i14); + JLabel More_op = new JLabel(i15); + More_op.setBounds(350,20,10,25); + p1.add(More_op); + + +//********************************************* NAME OF THE USER *********************************************** + + + JLabel name = new JLabel("Aagastya"); + name.setBounds(110,15,100,18); + name.setForeground(Color.white); + name.setFont(new Font("SAN_SERIF",Font.BOLD,21)); + p1.add(name); + + +//********************************************* STATUS OF THE USER ************************************************* + + + JLabel Status = new JLabel("Active Now"); + Status.setBounds(110,42,100,18); + Status.setForeground(Color.white); + Status.setFont(new Font("SAN_SERIF",Font.BOLD,14)); + p1.add(Status); + + +//************************************************** TEXT AREA ************************************************* + + + a1 = new JPanel(); + a1.setBounds(5,75,390,520); + t.add(a1); + + +//************************************************** USER CHAT ************************************************* + + + text = new JTextField(); + text.setBounds(2,599,280,40); + text.setFont(new Font("SAN_SERIF",Font.PLAIN,16)); + t.add(text); + + +//********************************************* SEND BUTTON ************************************************* + + JButton send = new JButton("Send"); + send.setBounds(285,599,110,40); + send.setBackground(new Color(7,94,84)); + send.setForeground(Color.white); + send.addActionListener(this); // Send button click + send.setFont(new Font("SAN_SERIF",Font.PLAIN,16)); + t.add(send); + +//-------------------------------------------------------------------------------------------------------------------------- + + + t.setSize(400,650); // setSize() fun in JFrame + t.setLocation(300,50); // need to change location as default location is top left + t.setUndecorated(true); // remove header (increases size of frame) + t.getContentPane().setBackground(Color.white); // Color class is under "awt" + t.setVisible(true); // Default visibility is false + } + + public void actionPerformed(ActionEvent ae) { + //new Client(); + try { + String out = text.getText(); + + JPanel p2 = formatLabel(out); + + a1.setLayout(new BorderLayout()); + + JPanel right = new JPanel(new BorderLayout()); + right.add(p2, BorderLayout.LINE_END); + vertical.add(right); // Add message in vertical box(For multiple messages) + vertical.add(Box.createVerticalStrut(15)); + + a1.add(vertical, BorderLayout.PAGE_START); // Append all this on text area + + + System.out.println(dout.toString()); + dout.writeUTF(out); + + text.setText(""); // To delete the text from chat area after it is sent + + + t.repaint(); // All three fun used to reload the frame + t.invalidate(); // so that sent texts would be seen + t.validate(); + } + catch(Exception e) + { + e.printStackTrace(); + } + + } + + public static JPanel formatLabel(String out) + { + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS)); + + JLabel output = new JLabel(out); + output.setFont(new Font("Tahoma",Font.PLAIN,16)); //"Tahoma" = Font name + // set font of text which user will send + output.setBackground(new Color(37,211,102)); + output.setOpaque(true); // For background color to be visible + + output.setBorder(new EmptyBorder(15,15,15,50)); + panel.add(output); + + + +//********************************************************** DATE AND TIME************************************************* + + + + Calendar cal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); + + JLabel time = new JLabel(); + time.setText(sdf.format(cal.getTime())); + + panel.add(time); + +//-------------------------------------------------------------------------------------------------------------------------- + + + return panel; + } + + public static void main(String[] args) + + { + new Server().setVisible(true); + try + { + ServerSocket skt = new ServerSocket(6001); // For real time chatting + + while(true) // condition for infinite chatting + { + Socket s = skt.accept(); + DataInputStream din = new DataInputStream(s.getInputStream()); // To receive messages + dout = new DataOutputStream(s.getOutputStream()); // To send messages + System.out.println(din.toString()); + while(true) + { + String meg = din.readUTF(); // To read a message + JPanel panel = formatLabel(meg); // Add on frame + + JPanel left = new JPanel(new BorderLayout()); + left.add(panel,BorderLayout.LINE_START); // Received messages on left + + vertical.add(left); + t.validate(); + } + } + } + catch(Exception e) + { + e.printStackTrace(); + } + + } + +} diff --git a/Connection/UI.java b/Connection/UI.java new file mode 100644 index 0000000..f407513 --- /dev/null +++ b/Connection/UI.java @@ -0,0 +1,266 @@ +package Connection; + +import Contact.*; +import Emergency.EmergencyEmail; +import MedicineAlarm.*; +import soundproject3package3.*; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.Font; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Timer; +import java.util.TimerTask; + +import javax.swing.JFrame; +import javax.swing.JLabel; + +public class UI extends JFrame implements ActionListener +{ + static JFrame f1 = new JFrame(); + JLabel l1,l2, lab_alarm, lab_contact,lab_chat,lab_music; + public UI() + { + + JPanel p1 = new JPanel(); + //JPanel = if we want to insert anything on frame + p1.setOpaque(true); + p1.setBackground(new Color(7,94,84)); + p1.setBounds(500,500,600,700); + p1.setLayout(null); + f1.add(p1); + + f1=new JFrame("Jio"); + + f1.setBackground( Color.black); + f1.setLayout(null); + + f1.setLayout(null); + + l1 = new JLabel(); + l1.setBounds(0,0,700,600); + l1.setLayout(null); + + + +//***************************************************************** TIME ************************************************************ + + + + JLabel timeLabel = new JLabel(); + timeLabel.setBackground(new Color(204,255,204)); + JLabel timeLabel1 = new JLabel(); + + timeLabel.setFont(new Font("Serif", Font.BOLD, 50)); + timeLabel1.setFont(new Font("Serif", Font.BOLD, 50)); + + // Create a new Timer object that will update the JLabel every second. + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + // Get the current date and time. + Date now = new Date(); + DateFormat df = new SimpleDateFormat("dd EEEEEE"); + DateFormat df2 = new SimpleDateFormat("HH:mm"); + + // Update the JLabel with the current date and time. + timeLabel.setText(df.format(now)); + timeLabel1.setText(df2.format(now)); + } + }, 0, 1000); + + timeLabel.setBounds(20,20,300,30); + timeLabel.setForeground(Color.darkGray); + timeLabel.setFont(new Font ("Airal",Font.BOLD,30)); + l1.add(timeLabel); + + timeLabel1.setBounds(20,50,300,30); + timeLabel1.setForeground(Color.darkGray); + timeLabel1.setFont(new Font ("Airal",Font.BOLD,30)); + l1.add(timeLabel1); + + +// ******************************************************** MUSIC ************************************************************ + + + + ImageIcon i4 = new ImageIcon(ClassLoader.getSystemResource("Connection/First_Page/radio.png")); + Image i5 = i4.getImage().getScaledInstance(150,150,Image.SCALE_DEFAULT); + ImageIcon i6 = new ImageIcon(i5); + JLabel music = new JLabel(i6); + music.setBounds(-50,230,300,300); + p1.add(music); + f1.add(music); + + + music.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + try { + new Player().setVisible(true); + } catch (UnsupportedAudioFileException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (LineUnavailableException e) { + throw new RuntimeException(e); + } + f1.setVisible(false); + } + } + ); + + lab_music = new JLabel("Music"); + lab_music.setBounds(70,460,200,30); + lab_music.setForeground(Color.darkGray); + lab_music.setFont(new Font ("Airal",Font.BOLD,20)); + l1.add(lab_music); + + + +// ******************************************************** ALARM ************************************************************ + + + + ImageIcon i1 = new ImageIcon(ClassLoader.getSystemResource("Connection/First_Page/alarm1.png")); + Image i2 = i1.getImage().getScaledInstance(150,150,Image.SCALE_DEFAULT); //Image class in "awt" + + ImageIcon i3 = new ImageIcon(i2); + + JLabel add_img = new JLabel(i3); + add_img.setBounds(120,230,300,300); + p1.add(add_img); + f1.add(add_img); + + add_img.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + new MedicineAlarm().setVisible(true); + f1.setVisible(false); + } + } + ); + + lab_alarm = new JLabel("Alarm"); + lab_alarm.setBounds(250,460,200,30); + lab_alarm.setForeground(Color.darkGray); + lab_alarm.setFont(new Font ("Airal",Font.BOLD,20)); + l1.add(lab_alarm); + + + +//********************************************************** EMERGENCY ************************************************************ + + + + ImageIcon i31 = new ImageIcon(ClassLoader.getSystemResource("Connection/First_Page/sirens.png")); + Image i32 = i31.getImage().getScaledInstance(60,60,Image.SCALE_DEFAULT); + ImageIcon i33 = new ImageIcon(i32); + JLabel emergency = new JLabel(i33); + emergency.setBounds(165,-110,300,300); + p1.add(emergency); + f1.add(emergency); + + + emergency.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + new EmergencyEmail(); + JOptionPane.showMessageDialog(f1,"Message sent") ; + f1.setVisible(false); + } + } + ); + +// ******************************************************** CONTACT ************************************************************ + + + + ImageIcon i7 = new ImageIcon(ClassLoader.getSystemResource("Connection/First_Page/Contact.png")); + Image i8 = i7.getImage().getScaledInstance(130,130,Image.SCALE_DEFAULT); + ImageIcon i9 = new ImageIcon(i8); + JLabel contact = new JLabel(i9); + contact.setBounds(120,8,300,300); + p1.add(contact); + f1.add(contact); + + + contact.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + new PhoneBook().setVisible(true); + f1.setVisible(false); + } + } + ); + + lab_contact = new JLabel("Contact"); + lab_contact.setBounds(235,240,200,30); + lab_contact.setForeground(Color.darkGray); + lab_contact.setFont(new Font ("Airal",Font.BOLD,20)); + l1.add(lab_contact); + + + +// ******************************************************** WHATSUP ************************************************************ + + + + ImageIcon i10 = new ImageIcon(ClassLoader.getSystemResource("Connection/First_Page/Chat.png")); + Image i11 = i10.getImage().getScaledInstance(130,130,Image.SCALE_DEFAULT); + ImageIcon i12 = new ImageIcon(i11); + JLabel whatsup = new JLabel(i12); + whatsup.setBounds(-45,8,300,300); + p1.add(whatsup); + f1.add(whatsup); + + whatsup.addMouseListener(new MouseAdapter() // close window on click + { + public void mouseClicked(MouseEvent ae) + { + f1.dispose(); + + new Server().setVisible(true); + new Client().setVisible(true); + } + } + ); + + lab_chat = new JLabel("Chat"); + lab_chat.setBounds(70,240,200,30); + lab_chat.setForeground(Color.darkGray); + lab_chat.setFont(new Font ("Airal",Font.BOLD,20)); + l1.add(lab_chat); + + + f1.add(l1); + + f1.setVisible(true); + f1.setSize(390,550); + f1.setLocation(500,100); + f1.setResizable(false); + } + + @Override + public void actionPerformed(ActionEvent e) { + + } + public static void main(String args[]) + { + new UI(); + } + } + diff --git a/Connection/icons/1.png b/Connection/icons/1.png new file mode 100644 index 0000000..3b8a42f Binary files /dev/null and b/Connection/icons/1.png differ diff --git a/Connection/icons/2.png b/Connection/icons/2.png new file mode 100644 index 0000000..5fbf1d8 Binary files /dev/null and b/Connection/icons/2.png differ diff --git a/Connection/icons/3.png b/Connection/icons/3.png new file mode 100644 index 0000000..f512f88 Binary files /dev/null and b/Connection/icons/3.png differ diff --git a/Connection/icons/3icon.png b/Connection/icons/3icon.png new file mode 100644 index 0000000..decb325 Binary files /dev/null and b/Connection/icons/3icon.png differ diff --git a/Connection/icons/Client.png b/Connection/icons/Client.png new file mode 100644 index 0000000..2d00140 Binary files /dev/null and b/Connection/icons/Client.png differ diff --git a/Connection/icons/Server.png b/Connection/icons/Server.png new file mode 100644 index 0000000..5807f58 Binary files /dev/null and b/Connection/icons/Server.png differ diff --git a/Connection/icons/arrow.jpg b/Connection/icons/arrow.jpg new file mode 100644 index 0000000..191dbe9 Binary files /dev/null and b/Connection/icons/arrow.jpg differ diff --git a/Connection/icons/bunty.jpeg b/Connection/icons/bunty.jpeg new file mode 100644 index 0000000..18dbcfc Binary files /dev/null and b/Connection/icons/bunty.jpeg differ diff --git a/Connection/icons/client15.png b/Connection/icons/client15.png new file mode 100644 index 0000000..d4b98c6 Binary files /dev/null and b/Connection/icons/client15.png differ diff --git a/Connection/icons/gaitonde.jpeg b/Connection/icons/gaitonde.jpeg new file mode 100644 index 0000000..139d89a Binary files /dev/null and b/Connection/icons/gaitonde.jpeg differ diff --git a/Connection/icons/logo.png b/Connection/icons/logo.png new file mode 100644 index 0000000..70e4b1e Binary files /dev/null and b/Connection/icons/logo.png differ diff --git a/Connection/icons/mirzapur.png b/Connection/icons/mirzapur.png new file mode 100644 index 0000000..327eeb8 Binary files /dev/null and b/Connection/icons/mirzapur.png differ diff --git a/Connection/icons/phone.png b/Connection/icons/phone.png new file mode 100644 index 0000000..c81fabb Binary files /dev/null and b/Connection/icons/phone.png differ diff --git a/Connection/icons/server15.png b/Connection/icons/server15.png new file mode 100644 index 0000000..abb1733 Binary files /dev/null and b/Connection/icons/server15.png differ diff --git a/Connection/icons/video.png b/Connection/icons/video.png new file mode 100644 index 0000000..d47d74a Binary files /dev/null and b/Connection/icons/video.png differ diff --git a/Contact/Main.java b/Contact/Main.java new file mode 100644 index 0000000..212c10c --- /dev/null +++ b/Contact/Main.java @@ -0,0 +1,8 @@ +//package Contact; +// +//public class Main { +// public static void main(String[] args) { +// PhoneBook bk = new PhoneBook(); +// +// } +//} \ No newline at end of file diff --git a/Contact/PhoneBook.java b/Contact/PhoneBook.java new file mode 100644 index 0000000..f99c7d8 --- /dev/null +++ b/Contact/PhoneBook.java @@ -0,0 +1,250 @@ +package Contact; + +import java.awt.*; +import java.awt.event.*; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.colorchooser.ColorSelectionModel; + +public class PhoneBook extends JFrame implements ActionListener { + private HashMap phoneBook; + private JPanel contentPane; + JTextField numberField; + JButton displayAllButton; + JButton searchButton; + JButton addButton; + JTextField nameField; + JTextField searchField; + JTextArea displayArea; + JScrollPane displayPane ; + + //String name,number; + + BufferedReader reader; + + + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + PhoneBook frame = new PhoneBook(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + public PhoneBook() { + phoneBook = new HashMap<>(); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 662, 793); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + setContentPane(contentPane); + contentPane.setLayout(null); + setResizable(false); + setLocationRelativeTo(null); + + JPanel panel = new JPanel(); + panel.setBackground(new Color(255, 228, 225)); + panel.setBounds(0, 0, 648, 814); + contentPane.add(panel); + panel.setLayout(null); + + JLabel lblNewLabel = new JLabel(""); + lblNewLabel.setIcon(new ImageIcon(ClassLoader.getSystemResource("Contact/phone_book.png"))); + lblNewLabel.setBackground(new Color(153, 204, 255)); + lblNewLabel.setFont(new Font("Serif", Font.BOLD, 35)); + lblNewLabel.setBounds(277, 10, 100, 109); + panel.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("CONTACTS"); + lblNewLabel_1.setBackground(new Color(153, 204, 255)); + lblNewLabel_1.setFont(new Font("Serif", Font.BOLD, 28)); + lblNewLabel_1.setBounds(251, 129, 206, 37); + panel.add(lblNewLabel_1); + + JLabel label = new JLabel("NAME :"); + label.setForeground(new Color(0, 128, 128)); + label.setBackground(new Color(153, 204, 255)); + label.setFont(new Font("Serif", Font.BOLD, 25)); + label.setBounds(33, 178, 114, 42); + panel.add(label); + + displayAllButton = new JButton("DISPLAY ALL CONTACTS"); + displayAllButton.setFont(new Font("Serif", Font.BOLD, 20)); + displayAllButton.setForeground(new Color(255, 240, 245)); + displayAllButton.setBackground(new Color(205, 133, 63)); + displayAllButton.setBounds(160, 489, 313, 53); + panel.add(displayAllButton); + displayAllButton.addActionListener(this); + + numberField = new JTextField(); + numberField.setFont(new Font("Serif", Font.PLAIN, 20)); + numberField.setForeground(new Color(0, 128, 128)); + numberField.setBackground(new Color(255, 240, 245)); + numberField.setBounds(229, 239, 313, 53); + panel.add(numberField); + numberField.setColumns(10); + + searchButton = new JButton("SEARCH"); + searchButton.setForeground(new Color(255, 240, 245)); + searchButton.setFont(new Font("Serif", Font.BOLD, 20)); + searchButton.setBackground(new Color(0, 139, 139)); + searchButton.setBounds(229, 442, 148, 37); + panel.add(searchButton); + searchButton.addActionListener(this); + + addButton = new JButton("ADD"); + addButton.setForeground(new Color(255, 240, 245)); + addButton.setFont(new Font("Serif", Font.BOLD, 20)); + addButton.setBackground(new Color(0, 139, 139)); + addButton.setBounds(229, 302, 148, 37); + panel.add(addButton); + addButton.addActionListener(this); + + + JLabel lblNumber = new JLabel("NUMBER :"); + lblNumber.setForeground(new Color(0, 128, 128)); + lblNumber.setFont(new Font("Serif", Font.BOLD, 25)); + lblNumber.setBackground(new Color(153, 204, 255)); + lblNumber.setBounds(33, 242, 148, 42); + panel.add(lblNumber); + + nameField = new JTextField(); + nameField.setForeground(new Color(0, 128, 128)); + nameField.setFont(new Font("Serif", Font.PLAIN, 20)); + nameField.setColumns(10); + nameField.setBackground(new Color(255, 240, 245)); + nameField.setBounds(230, 176, 313, 53); + panel.add(nameField); + + JLabel lblSearchName = new JLabel("SEARCH NAME :"); + lblSearchName.setForeground(new Color(0, 128, 128)); + lblSearchName.setFont(new Font("Serif", Font.BOLD, 25)); + lblSearchName.setBackground(new Color(153, 204, 255)); + lblSearchName.setBounds(10, 371, 206, 42); + panel.add(lblSearchName); + + searchField = new JTextField(); + searchField.setForeground(new Color(0, 128, 128)); + searchField.setFont(new Font("Serif", Font.PLAIN, 20)); + searchField.setColumns(10); + searchField.setBackground(new Color(255, 240, 245)); + searchField.setBounds(229, 368, 313, 53); + panel.add(searchField); + + displayArea = new JTextArea(); + displayArea.setBackground(new Color(255, 228, 225)); + displayArea.setBounds(10, 606, 629, 200); + displayArea.setFont(new Font("Serif", Font.PLAIN, 18)); + displayArea.setForeground(Color.BLACK); + panel.add(displayArea); + addButton.addActionListener(this); + + displayPane = new JScrollPane(displayArea); + displayPane.setBounds(10, 552, 629, 200); // Set preferred size + displayPane.setBorder(BorderFactory.createTitledBorder("CONTACTS :")); // Set border with title + panel.add(displayPane); + + // Load phone book from CSV file and store into hashmap named 'phonebook' + try { + reader = new BufferedReader(new FileReader("csvphone.csv")); + String line; + while ((line = reader.readLine()) != null) { + String[] parts = line.split(","); + if (parts.length == 2) { + phoneBook.put(parts[0], parts[1]); + } + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + + } + + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + + /*name = nameField.getText(); + number = numberField.getText();*/ + + if (e.getSource()==addButton) { + displayArea.append(""); + String name,number; + displayArea.setText(""); + name = nameField.getText(); + number = numberField.getText(); + + /*if (phoneBook.containsKey(name)) { + displayArea.append("NUMBER FOR " + name + " UPDATED TO " + number + "\n"); + + } + else { + displayArea.append("ADDED " + name + " WITH NUMBER " + number + "\n"); + + }*/ + displayArea.append("ADDED SUCCESSFULLY !"); + phoneBook.put(name, number); + + savePhoneBook(); + + + } + if (action.equals("SEARCH")) { + displayArea.setText(""); + String search = searchField.getText(); + String result = phoneBook.get(search); //searching using hashmap --> REDUCED TIME COMPLEXITY !! + if (result == null) { + displayArea.setText("NO RESULTS FOUND !\n"); + } else { + displayArea.setText(search + " ---> " + result + "\n"); + } + } + if(action.equals("DISPLAY ALL CONTACTS")) { + + displayArea.setText(""); + + Map sortedMap = new TreeMap<>(phoneBook); + for (Map.Entry entry : sortedMap.entrySet()) { + displayArea.append(entry.getKey() + "--->" + entry.getValue() + "\n"); + } + } + } + + public void savePhoneBook() { + // Save phone book to CSV file + try { + FileWriter writer = new FileWriter("csvphone.csv"); + //CSVWriter csvwrit = new CSVWriter(writer); + for (String key : phoneBook.keySet()) { + String value = phoneBook.get(key); + System.out.println(key+value); + //writer.append(key + "," + value + "\n"); + writer.append(key); + writer.append(","); + writer.append(value); + writer.append("\n"); + } + writer.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + +} diff --git a/Contact/phone_book.png b/Contact/phone_book.png new file mode 100644 index 0000000..0f32137 Binary files /dev/null and b/Contact/phone_book.png differ diff --git a/Emergency/EmergencyEmail.java b/Emergency/EmergencyEmail.java new file mode 100644 index 0000000..f597006 --- /dev/null +++ b/Emergency/EmergencyEmail.java @@ -0,0 +1,145 @@ +package Emergency; + +import javax.mail.*; +import javax.mail.internet.*; +import java.util.*; + +public class EmergencyEmail +{ + static Queue receiverQueue=new LinkedList<>(); + final String senderEmail = "daksha.kulkarni@cumminscollege.in"; //change email address + + final String senderPassword = "daksha23"; //change password + + final String emailSMTPserver = "smtp.gmail.com"; + + final String emailServerPort = "465"; + + String receiverEmail1 = null; + String receiverEmail2=null; + String receiverEmail3=null; + static String receiverEmail; + + static String emailSubject; + + + static String emailBody=null; + + public EmergencyEmail() { + + //receiver email + + + + //subject + + this.emailSubject = "Emergency"; + + //body + + this.emailBody =" Your Loved ones need your help..please look into the matter"; + + + Properties props = new Properties(); + + props.put("mail.smtp.user",senderEmail); + + props.put("mail.smtp.host", emailSMTPserver); + + props.put("mail.smtp.port", emailServerPort); + + props.put("mail.smtp.starttls.enable", "true"); + + props.put("mail.smtp.auth", "true"); + + props.put("mail.smtp.socketFactory.port", emailServerPort); + + props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); + + props.put("mail.smtp.socketFactory.fallback", "false"); + + @SuppressWarnings("removal") + + SecurityManager security = System.getSecurityManager(); + String receiverEmail1 = "daksha.kulkarni@cumminscollege.in"; + String receiverEmail2 = "saniya.dighe@cumminscollege.in"; + String receieverEmail3="gayatri.joshi@cumminscollege.in"; + + receiverQueue.add(receiverEmail1); + receiverQueue.add(receiverEmail2); + receiverQueue.add(receieverEmail3); + while(!receiverQueue.isEmpty()){ + String qemail=receiverQueue.peek(); + // new EmergencyEmail(qemail,subject,emailBody); + receiverEmail=qemail; + receiverQueue.remove(); + try { + + Authenticator auth = new SMTPAuthenticator(); + + Session session = Session.getInstance(props, auth); + + MimeMessage msg = new MimeMessage(session); + + msg.setText(emailBody); + + //System.out.println(emailBody); + + msg.setSubject(emailSubject); + + msg.setFrom(new InternetAddress(senderEmail)); + + + + msg.addRecipient(Message.RecipientType.TO, new InternetAddress(receiverEmail)); + + Transport.send(msg); + + System.out.println("Message sent successfully"); + + } + + catch (Exception e) + { + e.printStackTrace(); + } + } + + + } + + public class SMTPAuthenticator extends javax.mail.Authenticator + { + + public PasswordAuthentication getPasswordAuthentication() + { + return new PasswordAuthentication(senderEmail, senderPassword); + } + } + + void calling(){ + + + } + + public static void main(String args[]) + { + new EmergencyEmail(); + +// String emailBody="Your Loved ones need your help..please look into the matter"; +// String receiverEmail1 = "daksha.kulkarni@cumminscollege.in"; +// String receiverEmail2 = "saniya.dighe@cumminscollege.in"; +// String receieverEmail3="gayatri.joshi@cumminscollege.in"; +// String subject="Emergency"; +// receiverQueue.add(receiverEmail1); +// receiverQueue.add(receiverEmail2); +// receiverQueue.add(receieverEmail3); +// +// while(!receiverQueue.isEmpty()) +// { +// String qemail=receiverQueue.peek(); +// new EmergencyEmail(qemail,subject,emailBody); +// receiverQueue.remove(); +// } + } +} diff --git a/MedicineAlarm/MedicineAlarm.java b/MedicineAlarm/MedicineAlarm.java new file mode 100644 index 0000000..c550d82 --- /dev/null +++ b/MedicineAlarm/MedicineAlarm.java @@ -0,0 +1,273 @@ +package MedicineAlarm; + +import java.awt.*; +import java.io.File; +import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.text.*; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JLabel; +import javax.swing.ImageIcon; +import javax.swing.SwingConstants; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import javax.swing.JTextField; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JComboBox; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import java.time.format.DateTimeFormatter; +import java.time.LocalDateTime; + + + + +class SoundPlayer { + + public void play() throws Exception { + + // specify the sound file path + File soundFile = new File("C:\\Users\\DAKSHA\\Downloads\\file.wav"); + + // create a new AudioInputStream + AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile); + + // get a Clip object to play the sound file + Clip clip = AudioSystem.getClip(); + + // open the AudioInputStream to the clip + clip.open(audioIn); + + // start playing the sound file + clip.start(); + + // wait for the sound to finish playing + while (!clip.isRunning()) + Thread.sleep(2); + while (clip.isRunning()) + Thread.sleep(2); + + // clean up the clip when finished + clip.close(); + } +} + +public class MedicineAlarm extends JFrame implements ActionListener{ + + private JPanel contentPane; + JFrame f; + JLabel timlab; + JButton set; + JComboBox hh,mm; + JButton addbtn; + private JLabel lblNewLabel_3; + ArrayList addtime = new ArrayList<>(); + ArrayList Med = new ArrayList<>(); + private JTextField medf; + public String gett; + + + public void GUI(){ + addtime.add("12.30"); + Med.add("pentaprazole"); + addtime.add("22.09"); + Med.add("pentaprazole"); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + setBounds(450, 100, 450, 610); + contentPane = new JPanel(); + contentPane.setBackground(new Color(0, 0, 51)); + setResizable(false); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + setContentPane(contentPane); + contentPane.setLayout(null); + + + + JPanel panel = new JPanel(); + panel.setBackground(new Color(153, 204, 255)); + panel.setBounds(10, 10, 416, 553); + contentPane.add(panel); + panel.setLayout(null); + +// JLabel lblNewLabel = new JLabel(""); +// lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); +// lblNewLabel.setIcon(new ImageIcon(MedicineAlarm.class.getResource("/icons/icons8-alarm-clock-100.png"))); +// lblNewLabel.setBounds(159, 10, 108, 97); +// panel.add(lblNewLabel); + + ImageIcon i10 = new ImageIcon(ClassLoader.getSystemResource("MedicineAlarm/icons_med/alarm_med.png")); + Image i11 = i10.getImage().getScaledInstance(100,100,Image.SCALE_DEFAULT); + ImageIcon i12 = new ImageIcon(i11); + JLabel alarm_med = new JLabel(i12); + alarm_med.setBounds(159, 10, 108, 97); + panel.add(alarm_med); + + JLabel lblNewLabel_1 = new JLabel("HOUR"); + lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 15)); + lblNewLabel_1.setBounds(108, 150, 76, 27); + panel.add(lblNewLabel_1); + + JLabel lblNewLabel_1_1 = new JLabel("MINUTE"); + lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel_1_1.setFont(new Font("Tahoma", Font.PLAIN, 15)); + lblNewLabel_1_1.setBounds(223, 150, 76, 27); + panel.add(lblNewLabel_1_1); + + JList list = new JList(); + list.setBounds(56, 240, 1, 1); + panel.add(list); + + hh = new JComboBox(); + hh.setBackground(new Color(255, 255, 255)); + hh.setFont(new Font("Stencil", Font.PLAIN, 30)); + hh.setModel(new DefaultComboBoxModel(new String[] {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"})); + hh.setBounds(118, 187, 71, 66); + panel.add(hh); + + mm = new JComboBox(); + mm.setBackground(new Color(255, 255, 255)); + mm.setFont(new Font("Stencil", Font.PLAIN, 30)); + mm.setModel(new DefaultComboBoxModel(new String[] {"00", "01", "02 ", "03 ", "04 ", "05", "06", "07", "08", "09", "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", "58", "59"})); + mm.setMaximumRowCount(10); + mm.setBounds(233, 187, 71, 66); + panel.add(mm); + + set = new JButton("Set Alarm"); + set.setBackground(new Color(204, 255, 204)); + set.setFont(new Font("Times New Roman", Font.BOLD, 25)); + set.setBounds(230, 408, 165, 61); + set.addActionListener(this); + panel.add(set); + + timlab = new JLabel(""); + timlab.setFont(new Font("Tahoma", Font.PLAIN, 20)); + timlab.setHorizontalAlignment(SwingConstants.CENTER); + timlab.setBounds(72, 133, 251, 44); + panel.add(timlab); + + addbtn = new JButton("Add Alarm"); + addbtn.setBackground(new Color(204, 255, 204)); + addbtn.setFont(new Font("Times New Roman", Font.BOLD, 25)); + addbtn.addActionListener(this); + addbtn.setBounds(26, 408, 179, 61); + panel.add(addbtn); + + lblNewLabel_3 = new JLabel("MEDICINE :"); + lblNewLabel_3.setFont(new Font("Times New Roman", Font.BOLD, 20)); + lblNewLabel_3.setBounds(56, 283, 179, 27); + panel.add(lblNewLabel_3); + + medf = new JTextField(); + medf.setFont(new Font("Verdana", Font.BOLD, 25)); + medf.setBackground(new Color(153, 204, 255)); + medf.setBounds(55, 320, 313, 50); + panel.add(medf); + medf.setColumns(10); + } + public void snip() { + SoundPlayer sp =new SoundPlayer(); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); + LocalDateTime now = LocalDateTime.now(); + if(addtime.contains(dtf.format(now))) { + int ind=addtime.indexOf(dtf.format(now)); + String mednow= Med.get(ind); + try { + sp.play(); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + Message_frame mf=new Message_frame(); + mf.tf.setText(mednow); + mf.setVisible(true); + } + } + + + + public static void main(String[] args) { + + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + MedicineAlarm frame = new MedicineAlarm(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + + public MedicineAlarm() { + GUI(); + } + + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if (e.getSource()==set) { + SoundPlayer sp =new SoundPlayer(); + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); + LocalDateTime now = LocalDateTime.now(); + String selectedHH = (String)hh.getSelectedItem(); + String selectedMM = (String)mm.getSelectedItem(); + // concatenate the selected values to get the selected time + String selectedTime = selectedHH + ":" + selectedMM; + System.out.println("Selected Time: " + selectedTime); + System.out.println("Current Time: " + dtf.format(now)); + + do { + now = LocalDateTime.now(); // update the current time + }while(!dtf.format(now).equals(selectedTime)); + //medf.setText("Quick Timer mode"); + gett=medf.getText(); + if(dtf.format(now).equals(selectedTime)) { + try { + sp.play(); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + Message_frame mf= new Message_frame(); + mf.setVisible(true); + mf.tf.setText(gett); + + } + + } + else if(e.getSource()==addbtn){ + String selectedHH = (String)hh.getSelectedItem(); + String selectedMM = (String)mm.getSelectedItem(); + // concatenate the selected values to get the selected time + String selectedTime = selectedHH + ":" + selectedMM; + String medtext = medf.getText(); + addtime.add(selectedTime); + Med.add(medtext); + } + + + + } + +} diff --git a/MedicineAlarm/Message_frame.java b/MedicineAlarm/Message_frame.java new file mode 100644 index 0000000..4eb3591 --- /dev/null +++ b/MedicineAlarm/Message_frame.java @@ -0,0 +1,89 @@ +package MedicineAlarm; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import java.awt.Color; +import javax.swing.JLabel; +import javax.swing.SwingConstants; +import java.awt.Font; +import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import javax.swing.JTextField; + +public class Message_frame extends JFrame implements ActionListener { + + private JPanel contentPane; + JButton okbtn; + public JTextField tf; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Message_frame frame = new Message_frame(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + /** + * Create the frame. + */ + public Message_frame() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 434, 262); + contentPane = new JPanel(); + contentPane.setBackground(new Color(0, 0, 51)); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + setContentPane(contentPane); + contentPane.setLayout(null); + + JPanel panel = new JPanel(); + panel.setBackground(new Color(102, 204, 255)); + panel.setBounds(10, 10, 400, 205); + contentPane.add(panel); + panel.setLayout(null); + + JLabel lblNewLabel = new JLabel("TIME TO TAKE MEDICINE"); + lblNewLabel.setFont(new Font("Yu Gothic", Font.BOLD, 20)); + lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel.setBounds(31, 38, 349, 54); + panel.add(lblNewLabel); + + okbtn = new JButton("OK"); + okbtn.setBackground(new Color(255, 255, 204)); + okbtn.setVerticalAlignment(SwingConstants.BOTTOM); + okbtn.setFont(new Font("Yu Gothic", Font.BOLD, 20)); + okbtn.addActionListener(this); + okbtn.setBounds(150, 146, 112, 49); + panel.add(okbtn); + + tf = new JTextField(); + tf.setHorizontalAlignment(SwingConstants.CENTER); + tf.setFont(new Font("Tahoma", Font.PLAIN, 25)); + tf.setBackground(new Color(102, 204, 255)); + tf.setBounds(70, 82, 259, 37); + tf.setEditable(false); + panel.add(tf); + tf.setColumns(10); + } + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + if(e.getSource()==okbtn) { + this.dispose(); + } + } +} diff --git a/MedicineAlarm/icons_med/Alarm.png b/MedicineAlarm/icons_med/Alarm.png new file mode 100644 index 0000000..557f30b Binary files /dev/null and b/MedicineAlarm/icons_med/Alarm.png differ diff --git a/MedicineAlarm/icons_med/alarm_med.png b/MedicineAlarm/icons_med/alarm_med.png new file mode 100644 index 0000000..fc2824e Binary files /dev/null and b/MedicineAlarm/icons_med/alarm_med.png differ diff --git a/README.md b/README.md index e6bc571..6efc40f 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,68 @@ # Buffer-4.0 -Buffer is a Data Structures and Algorithms Project series, in which students can participate as mentees in teams of 3-4 people. -This year the themes on which students can create a project are- -1. Healthcare -2. Digital Society -3. Open Innovation -4. Custom data structure to store data +

TECHEASE : Senior Citizens

+ + +

Team Name: Inceptors


+Saniya Dighe(UCE2021416)(SY Comp)
+Daksha Kulkarni(UCE2021437)(SY Comp)
+Gayatri Joshi(UCE2021430)(SY Comp)

+ + +Theme: Open Innovation
+ +

About Project

+ + +Here we are with TECHEASE, which is an open innovation application for senior citizens. +Living in this technosavvy world, its difficult for elderly people to cope up with this evolving technology. Current interaction designs often feature illegible text, tiny targets, startling sounds, and other features that make the online world unfriendly to older users.so here is our genuine try to deal with this situation. +So TECHEASE is a user friendly java application with a strong base of various data structures such as arraylist,queue,hashmap and doubly circular linkedlist and with an appealing GUI using Java swing. +

+ +Drive Link to reports:https://drive.google.com/drive/u/1/folders/1fo6LzreVezqPBLvo-2F6B4BU_xee0Jbt
+Drive Link to Video: https://drive.google.com/drive/u/1/folders/1WJMbo4go9Rt9-Oi49ah_rUnZCcGBs-aJ
+ +

Brief Explanation

+

1.Here we have displayed the time and date as seen on our mobile phones using libraries such as Date-time format and calender. + +2.At the right corner, we see a buzzer which can be pressed in emergency situations. +It sends a mail to all the family members so that they get notified about the emergency. +The data structure which we used here is Queue.E-mail addresses of family members are stored in a queue.On pressing the buzzer emails are sent until the queue gets empty. + +3.Whatsup +This is a Client-Server chatting application based on Socket Programming.Using this users can connect with their loved ones. Here networking concepts are used where messages are port from server to client.The libraries used are : +ServerSocket , DataInput/outStream and many more. + +4.Contact : +It is a basic phonebook application created using HashMap.The key-value pair in the HashMap are Name and phonenum respectively ,keeping the time complexity of search operation constant.The entries are stored in a csv file which acts as a database. + +5.Radio : +Which is a music applet for entertainment purpose.We've created generic doubly circular linked list with are own methods.Each song is stored in a node. We can play, pause and move to next or previous song.At the end of the play list it loops back to the first song due to the circular nature of the linked list. + +6.Alarm : +Taking medicines on time is a neccessity.So to set a remainder we've built an alarm clock where we can set time and medicine name.Internally the entries are stored in array list. + +CONCLUSION : + +So this was our TECHEASE application. +Overall, this project has provided valuable insights into creating a techno-friendly world. +It has also highlighted the challenges faced by elderly people , and offers potential solutions to address these issues. + +Hope we have made technology a bit easier for our silver generation. +

+ + + + + + + + + + + + -This repository is created for all the teams to be able to upload their final project source code for the same. -While submitting, note that: -Each folder should have the name of the team and inside a readme file with team member details, (name, year, branch) and their theme. The readme file should also contain the link to their presentation as well as the drive link where both the report documents would be stored. -Happy Coding :) diff --git a/mygenericdoublylinkedlistpackage/MyDoublyLinkedList.java b/mygenericdoublylinkedlistpackage/MyDoublyLinkedList.java new file mode 100644 index 0000000..e3dd2bb --- /dev/null +++ b/mygenericdoublylinkedlistpackage/MyDoublyLinkedList.java @@ -0,0 +1,261 @@ +package mygenericdoublylinkedlistpackage; + +/** + + * Generic Doubly Linked List + * @param + */ +public class MyDoublyLinkedList { + private Node head; + private Node tail; + private int size; + + /** + + * class Node + */ +//-------------------------------------------------- + public class Node{ + private T data; + private Node next; + private Node prev; + + Node(){ + data = null; + next = null; + } + + Node(T data){ + this.data = data; + next = null; + } + + /** + * @return the next + */ + public Node getNext() { + return next; + } + + /** + * @param next the next to set + */ + public void setNext(Node next) { + this.next = next; + } + + /** + * @return the data + */ + public T getData() { + return data; + } + + /** + * @param data the data to set + */ + public void setData(T data) { + this.data = data; + } + + /** + * @return the prev + */ + public Node getPrev() { + return prev; + } + + /** + * @param prev the prev to set + */ + public void setPrev(Node prev) { + this.prev = prev; + } +//----------------------------------------------------------- + } + + public MyDoublyLinkedList() { + head = null; + tail = null; + size = 0; + } + + /** + * @param data + * Inserts at the front + */ + public void insertFront(T data){ + Node newNode = new Node(data); + + if (head != null) { + newNode.next = head; + } + + head = newNode; + size++; + return; + } + + /** + * @param data + * Inserts at the end + */ + public void insertEnd(T data){ + Node newNode = new Node(data); + +//Empty List + if (head == null) { + head = newNode; + tail = newNode; + size++; + return; + } + + tail.next = newNode; + newNode.setPrev(tail); + tail = newNode; + tail.next=head; + head.setPrev(tail); + + + size++; + return; + } + + /** + * Prints the list + * For data of Object type, To String method will be printed + */ + public void printList(){ + if (this.isEmpty()) { + return; + } + + Node curr = head; + int i = 0; + while(curr != null) { + i++; + System.out.println(" \t\t"+i+". "+curr.getData()); + curr = curr.next; + } + } + + /** + * @return Object data deleted + * Deletes from front + */ + public T deleteFront() { + if (head == null) { + System.out.println("Empty List"); + return null; //This can raise null pointer exception + } + + Node x = head; + head = head.next; + size--; + return x.data; //return data deleted + +//System.out.println("Element deleted"); + } + + /** + * @return Object data deleted + * Deletes from end + */ + public T deleteEnd () { + + if (head == null) { + System.out.println("Empty List"); + return null; //This can raise null pointer exception + } + + T deletedData = tail.getData(); + tail = tail.getPrev(); + tail.setNext(null); + + size--; + return deletedData; + + } + + /** + * @param pos + * @return deleted data + * Deletes node from position pos + */ + public T deletePos(int pos) { + if (head == null) { + System.out.println("Empty List"); + return null; //This can raise null pointer exception + } + + if (pos > size) { + System.out.println("Invalid position"); + return null; + } + + Node curr = head; + + for(int i=1; i l ; + SimpleAudioPlayer sap; + SongPath s1,s2,s3,s4,s5,s6; + String str1 = "Lag Jaa Gale"; + String str2 = "Yeh Raatein yeh mausam"; + String str3 = "Achha Ji Main Haari"; + String str4 = "Pal Pal Dil Ke Paas"; + String str5 = "Chhookar Mere Mann Ko"; + String str6= "Tera Mujhse hai"; + MusicPlayer() throws UnsupportedAudioFileException, IOException, LineUnavailableException{ + s1=new SongPath("C:\\Users\\DAKSHA\\Downloads\\Lag Jaa Gale.wav",str1); + s2=new SongPath("C:\\Users\\DAKSHA\\Downloads\\Yeh Ratein Yeh Mausam.wav",str2); + s3=new SongPath("C:\\Users\\DAKSHA\\Downloads\\Achha Ji Main Haari.wav",str3); + s4=new SongPath("C:\\Users\\DAKSHA\\Downloads\\Pal Pal Dil Ke Paas.wav",str4); + s5=new SongPath("C:\\Users\\DAKSHA\\Downloads\\Chookar Mere Mann Ko.wav",str5); + s6=new SongPath("C:\\Users\\DAKSHA\\Downloads\\Tera Mujhse Hai Pehle Ka Naata.wav",str6); + l = new MyDoublyLinkedList<>(); + l.insertEnd(s1); + l.insertEnd(s2); + l.insertEnd(s3); + l.insertEnd(s4); + l.insertEnd(s5); + l.insertEnd(s6); + + } + + + + +} \ No newline at end of file diff --git a/soundproject3package3/Player.java b/soundproject3package3/Player.java new file mode 100644 index 0000000..8406313 --- /dev/null +++ b/soundproject3package3/Player.java @@ -0,0 +1,195 @@ +package soundproject3package3; + +import java.awt.*; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import javax.swing.JLabel; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; +import javax.swing.ImageIcon; +import javax.swing.SwingConstants; +import javax.swing.JTextField; +import javax.swing.border.SoftBevelBorder; + +import mygenericdoublylinkedlistpackage.MyDoublyLinkedList; + +import javax.swing.border.BevelBorder; +import javax.swing.border.LineBorder; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import java.io.IOException; + +import javax.swing.JButton; +public class Player extends JFrame implements ActionListener{ + private JPanel contentPane; + private JTextField textField; + JButton prev,play,pause,next; + MusicPlayer mp = null; + MyDoublyLinkedList.Node curr; + private JTextField txtCarvaan; + + /** + * Launch the application. + */ + public static void main(String[] args) { + EventQueue.invokeLater(new Runnable() { + public void run() { + try { + Player frame = new Player(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + /** + * Create the frame. + * @throws LineUnavailableException + * @throws IOException + * @throws UnsupportedAudioFileException + */ + public Player() throws UnsupportedAudioFileException, IOException, LineUnavailableException { + mp = new MusicPlayer(); + curr=mp.l.getHead(); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setBounds(100, 100, 632, 573); + setResizable(false); + setLocationRelativeTo(null); + + contentPane = new JPanel(); + contentPane.setBackground(new Color(255, 255, 204)); + contentPane.setBorder(new LineBorder(new Color(0, 0, 0))); + setContentPane(contentPane); + contentPane.setLayout(null); + + JLabel lblNewLabel = new JLabel(""); + lblNewLabel.setBackground(new Color(255, 255, 204)); + lblNewLabel.setIcon(new ImageIcon(ClassLoader.getSystemResource("soundproject3package3/images_music/radio.png"))); + lblNewLabel.setBounds(172, 11, 275, 206); + contentPane.add(lblNewLabel); + + textField = new JTextField(""); + textField.setBackground(new Color(255, 255, 204)); + textField.setFont(new Font("Sitka Text", Font.BOLD, 30)); + textField.setBounds(57, 298, 390, 53); + textField.setEditable(false); + + contentPane.add(textField); + textField.setColumns(10); + + prev = new JButton(""); + prev.setIcon(new ImageIcon(ClassLoader.getSystemResource("soundproject3package3/images_music/prev.png"))); + prev.setBackground(new Color(255, 255, 204)); + prev.setBounds(46, 373, 87, 82); + prev.addActionListener(this); + contentPane.add(prev); + + + play = new JButton(""); + play.setIcon(new ImageIcon(ClassLoader.getSystemResource("soundproject3package3/images_music/play.png"))); + play.setBackground(new Color(255, 255, 204)); + play.setBounds(217, 373, 80, 82); + contentPane.add(play); + play.addActionListener(this); + + pause = new JButton(""); + pause.setIcon(new ImageIcon(ClassLoader.getSystemResource("soundproject3package3/images_music/pause.png"))); + pause.setBackground(new Color(255, 255, 204)); + pause.setBounds(336, 373, 87, 82); + pause.addActionListener(this); + contentPane.add(pause); + + next = new JButton(""); + next.setIcon(new ImageIcon(ClassLoader.getSystemResource("soundproject3package3/images_music/next.png"))); + next.setBackground(new Color(255, 255, 204)); + next.setBounds(484, 373, 87, 82); + next.addActionListener(this); + contentPane.add(next); + + txtCarvaan = new JTextField("C A R V A A N"); + txtCarvaan.setForeground(new Color(255, 102, 102)); + txtCarvaan.setFont(new Font("Sitka Text", Font.BOLD | Font.ITALIC, 30)); + txtCarvaan.setEditable(false); + txtCarvaan.setColumns(10); + txtCarvaan.setBackground(new Color(255, 255, 204)); + txtCarvaan.setBounds(208, 227, 204, 44); + contentPane.add(txtCarvaan); + } + + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + + if(e.getSource()==play) { + + try { + curr.getData().playSong(5); + + } catch (UnsupportedAudioFileException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (LineUnavailableException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + textField.setText(curr.getData().songName); + } + + if(e.getSource()==pause) { + curr.getData().s1.clip.close(); + textField.setText("~~~ AUDIO PAUSED ~~~"); + + } + + + if(e.getSource()==prev) { + curr.getData().s1.clip.close(); + curr=curr.getPrev(); + try { + curr.getData().playSong(5); + } catch (UnsupportedAudioFileException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (LineUnavailableException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + textField.setText(curr.getData().songName); + } + + if(e.getSource()==next) { + curr.getData().s1.clip.close(); + curr=curr.getNext(); + + try { + + curr.getData().playSong(5); + } catch (UnsupportedAudioFileException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } catch (LineUnavailableException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + textField.setText(curr.getData().songName); + } + + } +} \ No newline at end of file diff --git a/soundproject3package3/SongPath.java b/soundproject3package3/SongPath.java new file mode 100644 index 0000000..8cc426c --- /dev/null +++ b/soundproject3package3/SongPath.java @@ -0,0 +1,62 @@ +package soundproject3package3; + +import java.io.IOException; +import java.util.Scanner; + +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; + +import soundsystempackage.SimpleAudioPlayer; + +public class SongPath { + Scanner sc; + String path; + String songName; + SimpleAudioPlayer s1; + + SongPath(String path, String songName) throws UnsupportedAudioFileException, IOException, LineUnavailableException { + sc = new Scanner(System.in); + this.path = path; + this.songName = songName; + + } + + /** + * @throws UnsupportedAudioFileException + * @throws IOException + * @throws LineUnavailableException Plays a single song Clip + * + */ + void playSong(int c) throws UnsupportedAudioFileException, IOException, LineUnavailableException { + + s1 = new SimpleAudioPlayer(path); + + /* + * while (true) { + * + * System.out. + * println("Song Options:\nStop the song to go to the previous or next one"); + * System.out.println("1. PAUSE"); System.out.println("2. RESUME"); + * System.out.println("3. RESTART"); System.out.println("4. STOP"); + * + * + * + { break; } } + */ + // + + s1.gotoChoice(c); +// if(c==4) +// s1.resetAudioStream(); + + + + return; + + } + + public String toString() { + return String.format("%s", songName); + + } +} \ No newline at end of file diff --git a/soundproject3package3/images_music/next.png b/soundproject3package3/images_music/next.png new file mode 100644 index 0000000..2d83915 Binary files /dev/null and b/soundproject3package3/images_music/next.png differ diff --git a/soundproject3package3/images_music/pause.png b/soundproject3package3/images_music/pause.png new file mode 100644 index 0000000..27d6171 Binary files /dev/null and b/soundproject3package3/images_music/pause.png differ diff --git a/soundproject3package3/images_music/play.png b/soundproject3package3/images_music/play.png new file mode 100644 index 0000000..36407d8 Binary files /dev/null and b/soundproject3package3/images_music/play.png differ diff --git a/soundproject3package3/images_music/prev.png b/soundproject3package3/images_music/prev.png new file mode 100644 index 0000000..801922f Binary files /dev/null and b/soundproject3package3/images_music/prev.png differ diff --git a/soundproject3package3/images_music/radio.png b/soundproject3package3/images_music/radio.png new file mode 100644 index 0000000..3741573 Binary files /dev/null and b/soundproject3package3/images_music/radio.png differ diff --git a/soundsystempackage/SimpleAudioPlayer.java b/soundsystempackage/SimpleAudioPlayer.java new file mode 100644 index 0000000..94b5314 --- /dev/null +++ b/soundsystempackage/SimpleAudioPlayer.java @@ -0,0 +1,210 @@ +package soundsystempackage; + +import java.io.File; + +import java.io.IOException; +import java.util.Scanner; + +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; + +/** + + *class that stores path of specific song and plays it + */ +public class SimpleAudioPlayer +{ + + // to store current position + public Long currentFrame; + public Clip clip; + + // current status of clip + String status = ""; + + AudioInputStream audioInputStream; + String filePath = " "; + + /** + * @param newFilePath + * @throws UnsupportedAudioFileException + * @throws IOException + * @throws LineUnavailableException + * Constructor to initialize streams and clip + * + */ + public SimpleAudioPlayer(String newFilePath) throws UnsupportedAudioFileException, IOException, LineUnavailableException + { + filePath = newFilePath; +// create AudioInputStream object + audioInputStream = + AudioSystem.getAudioInputStream(new File(newFilePath).getAbsoluteFile()); + +// create clip reference + clip = AudioSystem.getClip(); + +// open audioInputStream to the clip + + } + + /** + * @param c choice + * @throws IOException + * @throws LineUnavailableException + * @throws UnsupportedAudioFileException + * Work as the user enters his choice + */ + public void gotoChoice(int c) throws IOException, LineUnavailableException, UnsupportedAudioFileException + { + switch (c) + { + case 1: + pause(); + break; + + case 2: + try { + resumeAudio(); + }catch(Exception e) { + e.printStackTrace(); + } + break; + case 3: + restart(); + break; + + case 4: + stop(); + resetAudioStream(); + break; + + case 5: + play(); + break; + + default: + break; + } + + } + + /** + * Method to play the audio, sets status to play + * @throws IOException + * @throws LineUnavailableException + */ + public void play() throws LineUnavailableException, IOException + { + clip.open(audioInputStream); + + clip.loop(Clip.LOOP_CONTINUOUSLY); + clip.start(); + status = "play"; + } + + /** + * Method to pause the audio + */ + public void pause() + { + if (status.equals("paused")) + { +//System.out.println("audio is already paused"); + return; + } + this.currentFrame = this.clip.getMicrosecondPosition(); + System.out.println(currentFrame); + clip.stop(); + System.out.println(clip); + status = "paused"; + System.out.println(status); + } + + /** + * @throws UnsupportedAudioFileException + * @throws IOException + * @throws LineUnavailableException + * Method to resume the audio + */ + public void resumeAudio() throws UnsupportedAudioFileException, + IOException, LineUnavailableException + { + if (status.equals("play")) + { + System.out.println("Audio is already "+ "being played"); + return; + } + clip.close(); + resetAudioStream(); + clip.setMicrosecondPosition(currentFrame); + this.play(); + + } + + /** + * @throws IOException + * @throws LineUnavailableException + * @throws UnsupportedAudioFileException + * Method to restart the audio + */ + public void restart() throws IOException, LineUnavailableException, UnsupportedAudioFileException + { + clip.stop(); + clip.close(); + resetAudioStream(); + currentFrame = 0L; + clip.setMicrosecondPosition(0); + this.play(); + } + + /** + * @throws UnsupportedAudioFileException + * @throws IOException + * @throws LineUnavailableException + * Method to stop the audio + */ + public void stop() throws UnsupportedAudioFileException, IOException, LineUnavailableException + { + currentFrame = 0L; + clip.stop(); + clip.close(); + } + + /** + * @param c + * @throws UnsupportedAudioFileException + * @throws IOException + * @throws LineUnavailableException + * Method to jump over a specific part + */ + public void jump(long c) throws UnsupportedAudioFileException, IOException, LineUnavailableException + { + if (c > 0 && c < clip.getMicrosecondLength()) + { + clip.stop(); + clip.close(); + resetAudioStream(); + currentFrame = c; + clip.setMicrosecondPosition(c); + this.play(); + } + } + + /** + * @throws UnsupportedAudioFileException + * @throws IOException + * @throws LineUnavailableException + * Method to reset audio stream + */ + public void resetAudioStream() throws UnsupportedAudioFileException, IOException, LineUnavailableException + { + audioInputStream = AudioSystem.getAudioInputStream( + new File(filePath).getAbsoluteFile()); + clip.open(audioInputStream); + clip.loop(Clip.LOOP_CONTINUOUSLY); + } + +} \ No newline at end of file