Commit 1fd406a4 authored by amsen's avatar amsen

init

parents
Pipeline #631 failed with stages
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class ChatArea extends JTextArea{
private static final int COL = 30, ROW = 10;
private String text;
public ChatArea() {
super(ROW, COL);
text = "";
this.setEditable(false);
this.setLineWrap(true);
}
public void addText(String sender, String message){
text = text + (text.equals("") ? "" : "\n") + sender + ": " + message;
this.setText(text);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
ChatArea chatArea = new ChatArea();
chatArea.addText("ali", "salam!!!!!");
chatArea.addText("amsen", "siloom!!!!!");
chatArea.addText("sadegh", "wooow!!!!!");
chatArea.addText("amsen","iln");
frame.add(chatArea);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
public class LoginPage extends JFrame{
private final String WINDOWS_TITLE = "Login page";
private final int WIDTH = 500, HEIGHT = 200;
private final int X = 100, Y = 100;
private JTextField usernamet;
private JButton loginb;
private JLabel usernamel;
public LoginPage(){
super();
this.setTitle(WINDOWS_TITLE);
this.setLayout(new GridLayout(3, 1));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(WIDTH, HEIGHT);
this.setLocation(X, Y);
usernamel = new JLabel();
usernamel.setText("username");
usernamet = new JTextField();
usernamel = new JLabel();
usernamel.setText("username");
loginb = new JButton();
loginb.setText("login");
add(usernamel);
add(usernamet);
add(loginb);
this.setVisible(true);
}
public static void main(String[] args){
LoginPage tmp = new LoginPage();
}
}
\ No newline at end of file
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
OnlineList onlineList = new OnlineList();
ChatArea chatArea = new ChatArea();
TypeArea typeArea = new TypeArea();
frame.add(onlineList, BorderLayout.WEST);
frame.add(chatArea, BorderLayout.CENTER);
frame.add(typeArea, BorderLayout.SOUTH);
onlineList.addPerson("ali");
onlineList.addPerson("amsen");
chatArea.addText("amsen","salam!");
frame.setSize(500, 500);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
public class OnlineList extends JPanel{
private JLabel label;
private ArrayList<JLabel> onlinePersons;
public OnlineList(){
super();
onlinePersons = new ArrayList<>();
this.setLayout(new GridLayout(20, 1));
label = new JLabel("online persons");
label.setOpaque(true);
label.setBackground(Color.ORANGE);
label.setForeground(Color.WHITE);
add(label);
}
public void addPerson(String s){
onlinePersons.add(new JLabel(s));
add(onlinePersons.get(onlinePersons.size()-1));
}
public void removePerson(String s){
for(int i=0 ; i<onlinePersons.size() ; i++)
if(onlinePersons.get(i).getText().equals(s)){
onlinePersons.remove(i);
remove(i+1);
break;
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
OnlineList onlineList = new OnlineList();
onlineList.addPerson("hasan");
onlineList.addPerson("nilo");
onlineList.addPerson("salam");
onlineList.removePerson("nilo");
onlineList.removePerson("salam");
frame.add(onlineList);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
import javax.swing.*;
import java.awt.*;
public class TypeArea extends JPanel{
private JTextField message;
private JButton send;
public TypeArea(){
super();
this.setLayout(new GridLayout(1, 2));
message = new JTextField("type your message here");
send = new JButton("send!");
add(message);
add(send);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
TypeArea typeArea = new TypeArea();
frame.add(typeArea);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment