0% found this document useful (0 votes)
4 views

Homework 1

java hw

Uploaded by

jgr102005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Homework 1

java hw

Uploaded by

jgr102005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

AMERICAN UNIVERSITY OF SCIENCE & TECHNOLOGY

FACULTY OF ENGINEERING & COMPUTER SCIENCE

CSI250L / ICT311L – Programming II Lab


Section A

By

Joelle Al-Rammah

ID#22330132

Fall Term 2024-2025

Submitted to
Samir Saad

Bhamdoun, Lebanon
December 12, 2024

Homework 1
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class SwingApplication {


public static void main(String[] args) {
JFrame application = new JFrame();
application.setTitle("My First Application");
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setLocationRelativeTo(null);

JPanel MotherPanel = new JPanel();


BorderLayout bLayout = new BorderLayout();
MotherPanel.setLayout(bLayout);

JPanel buttonsPanel = new JPanel();


JPanel textPanel = new JPanel();
JPanel northPanel = new JPanel();
JPanel westPanel = new JPanel();
JPanel eastPanel = new JPanel();

MotherPanel.add(buttonsPanel, BorderLayout.SOUTH);
MotherPanel.add(textPanel, BorderLayout.CENTER);
MotherPanel.add(northPanel, BorderLayout.NORTH);
MotherPanel.add(westPanel, BorderLayout.WEST);
MotherPanel.add(eastPanel, BorderLayout.EAST);

JLabel label = new JLabel("Name:");


JTextField textField = new JTextField(20);
JButton btok = new JButton("Ok");

textPanel.add(label);
textPanel.add(textField);
buttonsPanel.add(btok);

JComboBox<String> comboBox = new JComboBox<>(new String[]{"Option 1", "Option 2", "Option 3"});
JCheckBox checkBox = new JCheckBox("Check me");
JTextField additionalField = new JTextField(15);

northPanel.add(new JLabel("North Panel"));


northPanel.add(comboBox);

westPanel.add(new JLabel("West Panel"));


westPanel.add(checkBox);

eastPanel.add(new JLabel("East Panel"));


eastPanel.add(additionalField);
btok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text = textField.getText();
System.out.println("Text entered: " + text);
}
});

application.add(MotherPanel);
application.pack();
application.setVisible(true);
}
}

You might also like