0% found this document useful (0 votes)
3 views6 pages

Hashing Implementation in Java

The document contains Java code for a simple hashing application using a graphical user interface (GUI). It allows users to input a key and a value, which are then stored in an array using a basic hashing technique with collision handling. The application displays the current values in two lists and updates the remaining slots available for input.

Uploaded by

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

Hashing Implementation in Java

The document contains Java code for a simple hashing application using a graphical user interface (GUI). It allows users to input a key and a value, which are then stored in an array using a basic hashing technique with collision handling. The application displays the current values in two lists and updates the remaining slots available for input.

Uploaded by

wijilad205
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Activity: Hashing

Name: Joaquim Muhongo


CODE
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];

public class Hash extends JFrame implements ActionListener {


int num1 = 0;
int key = 0;
int number = 10;
String value = "";
String[] arr = new String[15];
ArrayList<String> here = new ArrayList<String>();
//Labels
private JLabel lblkey = new JLabel("Key: ");
private JLabel lblvalue = new JLabel("Value: ");
private JLabel lblremain = new JLabel("Remaining: ");
private JLabel remaining = new JLabel("");
private JList list,list2;
private JTextField KeyField = new JTextField();
private JTextField ValueField = new JTextField();

private JButton btnSubmit = new JButton("Submit");

private DefaultListModel listModel;


private DefaultListModel listModel2;
ListSelectionModel listMode, listmode2;
//object
listOperation hash= new listOperation();

//constructor
public Hash(String title) {
super(title);
setLayout(new BorderLayout());
setLayout(new FlowLayout());
// Just for refresh :) Not optional!
setSize(399,399);
setSize(300,300);

listModel = new DefaultListModel();


listModel2 = new DefaultListModel();
list = new JList(listModel);
list2 = new JList(listModel2);

JLabel headline = new JLabel("Hashing");


[Link](new Font("Century Gothic", [Link],20));
[Link](new Color(32, 50, 57));
[Link](new Font("Century Gothic", [Link],20));
[Link](new Color(32, 50, 57));
[Link](new Font("Century Gothic", [Link],20));
[Link](new Color(32, 50, 57));
[Link](new Font("Century Gothic", [Link],20));
[Link](new Color(32, 50, 57));
[Link](new Font("Century Gothic", [Link],20));
[Link](new Color(32, 50, 57));
//SETBOUNDS
[Link](40,20,100,100);
[Link](110,60,130,25);
[Link](40,60,100,100);
[Link](110,100,130,25);
[Link](260,20,130,100);
[Link](390,20,130,100);
[Link](210,10,200,30);
[Link](260,100,150,30);
[Link](this);

JScrollPane listScrollPane = new JScrollPane(list);


[Link](30,150,200,250);
[Link](new Dimension(150,50));

JScrollPane listScrollPane1 = new JScrollPane(list2);


[Link](250,150,200,250);
[Link](new Dimension(150,50));
//ADD
add(lblkey);
add(KeyField);
add(lblvalue);
add(ValueField);
add(lblremain);
add(remaining);
add(headline);
add(listScrollPane);
add(listScrollPane1);
add(btnSubmit);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setSize(500,500);
setVisible(true);
}

public void actionPerformed(ActionEvent event) {


boolean core = true;
if(btnSubmit == [Link]()){
number--;
[Link]([Link](number));
key = [Link]([Link]());
key = key % 15;
value = [Link]();
while(core == true) {
if(arr[key] == null) {
arr[key] = value;
core = false;
} else {
key++;
if(key == 15){
key = 0;
}
}
}
[Link]();
[Link]();
for(int x = 0; x < [Link]; x++){
if(arr[x] != null){
[Link](arr[x]);
}
}

for (int x = [Link] - 1; x >= 0; x-- ) {


if(arr[x] != null) {
[Link](arr[x]);
}
}
}
[Link]("");
[Link]("");
}

public static void main(String[] args) {


Container list = new Hash("Hashing");
}
}

OUTPUT

You might also like