0% found this document useful (0 votes)
61 views8 pages

Java Lab7

The document defines a Java class called "lab7" that determines the union and intersection of sets of integers. It creates two tree sets ("s1" and "s2") to hold numbers from text areas, and additional sets for the union and intersection results. Methods are defined to add the numbers to the sets, perform the union by combining both sets, and intersect the sets by keeping only the common elements. The class displays the input and output sets using labels and text areas, and buttons to trigger the union and intersection methods.

Uploaded by

uohikjb jbjkbkj
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)
61 views8 pages

Java Lab7

The document defines a Java class called "lab7" that determines the union and intersection of sets of integers. It creates two tree sets ("s1" and "s2") to hold numbers from text areas, and additional sets for the union and intersection results. Methods are defined to add the numbers to the sets, perform the union by combining both sets, and intersect the sets by keeping only the common elements. The class displays the input and output sets using labels and text areas, and buttons to trigger the union and intersection methods.

Uploaded by

uohikjb jbjkbkj
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/ 8

st. gr.

C-121

Bordeianu Mihail

Varianta 3

Defini o clas Set bazat colecii pentru un set de numere ntregi, Creai metodele de determinare
a uniunii i intersectiei de seturi .

import java.util.TreeSet;

public class lab7 extends javax.swing.JFrame {

//3 multimi

TreeSet s1 = new TreeSet();

TreeSet s2 = new TreeSet();

// TreeSet s3 = new TreeSet();

//uniunea

TreeSet sIntersectia = new TreeSet();

//intersectia

TreeSet sUniunea = new TreeSet();

public lab7() {

initComponents();

}
//esirea elementelor la ecran

public void AddToSet()

String str1 [] = jTextArea1.getText().split("\n");

String str2 [] = jTextArea2.getText().split("\n");

// String str3 [] = jTextArea3.getText().split("\n");

for(int i=0; i<str1.length; i++)

s1.add(str1[i]);

for(int i=0; i<str2.length; i++)

s2.add(str2[i]);

/* for(int i=0; i<str3.length; i++)

s3.add(str3[i]);*/

//Uniunea

public void Uniunea()

sUniunea.addAll(s1);

sUniunea.addAll(s2);

// sUniunea.addAll(s3);

//Intersectia

public void Intersectia()

sIntersectia.addAll(s1);

sIntersectia.retainAll(s2);

// sIntersectia.retainAll(s3);

}
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();

jTextArea1 = new javax.swing.JTextArea();

jScrollPane2 = new javax.swing.JScrollPane();

jTextArea2 = new javax.swing.JTextArea();

jScrollPane4 = new javax.swing.JScrollPane();

jTextArea4 = new javax.swing.JTextArea();

jButton1 = new javax.swing.JButton();

jButton2 = new javax.swing.JButton();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle("lab_7 Bordeian Mihail gr. C-121");

setBounds(new java.awt.Rectangle(200, 200, 0, 0));

jTextArea1.setColumns(20);

jTextArea1.setLineWrap(true);

jTextArea1.setRows(5);

jTextArea1.setText("3\n2\n1\n");

jScrollPane1.setViewportView(jTextArea1);

jTextArea2.setColumns(20);

jTextArea2.setLineWrap(true);
jTextArea2.setRows(5);

jTextArea2.setText("4\n2\n5");

jScrollPane2.setViewportView(jTextArea2);

jTextArea4.setColumns(20);

jTextArea4.setLineWrap(true);

jTextArea4.setRows(5);

jScrollPane4.setViewportView(jTextArea4);

jButton1.setForeground(new java.awt.Color(0, 0, 153));

jButton1.setText("Uniunea");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

});

jButton2.setForeground(new java.awt.Color(0, 0, 153));

jButton2.setText("Intersectia");

jButton2.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton2ActionPerformed(evt);

});

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

jLabel1.setForeground(new java.awt.Color(0, 0, 153));

jLabel1.setText(" Determinarea Uniunii si Intersectiei");


jLabel2.setText("Rezultatul:");

jLabel3.setText("1-a Multime");

jLabel4.setText("2-a Multime");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(43, 43, 43)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jButton1)

.addComponent(jLabel3))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jButton2)

.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2))))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(22, 22, 22)

.addComponent(jLabel1)

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel3)

.addGap(14, 14, 14))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel4)

.addComponent(jLabel2))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(24, 24, 24)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jButton1)
.addComponent(jButton2))

.addContainerGap(111, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

AddToSet();

Uniunea();

jTextArea4.setText(sUniunea.toString());

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

AddToSet();

Intersectia();

jTextArea4.setText(sIntersectia.toString());

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new lab7().setVisible(true);

});

}
// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JButton jButton2;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JScrollPane jScrollPane4;

private javax.swing.JTextArea jTextArea1;

private javax.swing.JTextArea jTextArea2;

private javax.swing.JTextArea jTextArea4;

// End of variables declaration

You might also like