Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

setlist arraylist java swing example

import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import javax.swing.JList;
import java.awt.event.*;
import java.util.ArrayList;
import java.io.*;
import java.util.*;

public class inventory extends JApplet implements MouseListener {

public static String newline;
public static JList list;
int gold = 123;

    public void init() {



ArrayList<String> arr = new ArrayList<String>();
arr.add("Hatchet");
arr.add("Sword");
arr.add("Shield");
arr.add(gold + " Gold");
System.out.println("You have " + arr.size() + " items in your inventory.");
showInventory(arr);



        list = new JList(arr);

        add(list);

        list.addMouseListener(this);

        list.setVisible(true);

    }

public static void showInventory (ArrayList<String> theList) {
for (int i = 0; i < theList.size(); i++) {
System.out.println(theList.get(i));
}
}


    public void mousePressed(MouseEvent e) { }

    public void mouseReleased(MouseEvent e) {
        Object index = list.getSelectedValue();
       System.out.println("You have selected: " + index);
    }

    public void mouseEntered(MouseEvent e) { }

    public void mouseExited(MouseEvent e) { }

    public void mouseClicked(MouseEvent e) { }




    public void paint(Graphics g) {

    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: more parameters java sql @PathVariable 
Java :: java platform runlater keeps running 
Java :: number guessing game in java using oops 
Java :: retrofit with api key post 
Java :: gradle project load test data json file with jackson 
Java :: os compatible java path separator 
Java :: unlock the screen 
Java :: oxygen cylinder management program in java 
Java :: OCA Exam Questions 
Java :: spinner android add underline like edittext 
Java :: download sources and javadoc 
Java :: java string replace last 4 characters 
Java :: hybrid inheritance in java 
Java :: resources/android/xml/network_security_config.xml 
Java :: JDA message 
Java :: Java Shuffling Using shuffle() 
Java :: convert jython object to java object 
Java :: how to count an replace string in java 
Java :: Child inside NestedScrollView not cover full height of screen 
Java :: calculate values of array 
Java :: android how to change focus on confirm button on keyboard 
Java :: Returning an Array from a Method 
Java ::         System.out.println("Welcone to GeeksforGeeks"); 
Java :: Merging 2 sorted arrays (edge cases2) 
Java :: Algorithms - transformation 
Java :: difference between set and list in java 
Java :: accessdeniedexception amplify init 
Java :: disable listview readonly 
Java :: org.springframework.data.mapping.model.mappinginstantiationexception: failed to instantiate java.util.list using constructor no_constructor with arguments 
Java :: Note: C:flutter..path_provider_android-2.0.11androidsrcmainjavaioflutterpluginspathproviderPathProviderPlugin.java uses unchecked or unsafe operations 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =