Käynnissä

JAVA Help

Create a Swing application that looks and behaves like a class already built.

Complete the following code by adding appropriate ActionListeners to each button or modifying the current ActionListeners to make this program complete. The functionality you are looking for is the following:

The Previous button will iterate through the data array moving to the previous array element each time the button is clicked and will then update the GUI with the newly selected data. If the Previous button is selected while the array is currently positioned at the first element, your program should then move the last element and update the display with the newly selected data.

The Next button will iterate through the data array moving to the next array element each time the button is clicked and will then update the GUI with the newly selected data. If the Next button is selected while the array is currently positioned at the last element, your program should then move the first element and update the display with the newly selected data.

When the Reset button is selected you should move to the first element in the array and update the display.

import javax.swing.*;

import java.awt.*;

class Assignment_02Source extends JFrame{

private JButton buttonPrev=new JButton("Prev");

private JButton buttonReset=new JButton("Reset");

private JButton buttonNext=new JButton("Next");

private JLabel labelHeader=new JLabel("Database Browser",[url removed, login to view]);

private JLabel labelName=new JLabel("Name");

private JLabel labelAddress=new JLabel("Address");

private JLabel labelCity=new JLabel("City");

private JLabel labelState=new JLabel("State");

private JLabel labelZip=new JLabel("Zip");

private JTextField textFieldName=new JTextField();

private JTextField textFieldAddress=new JTextField();

private JTextField textFieldCity=new JTextField();

private JTextField textFieldState=new JTextField();

private JTextField textFieldZip=new JTextField();

DataClass [] DataClassArray = {new DataClass("Fred", "Wayne", "101 Here", "NE", "55551"),

new DataClass("Goerge", "Thomas", "102 There", "ME", "55552"),

new DataClass("Mike", "Johnson", "103 No Where", "OK", "55553")};

int arrayPointer = 0;

public Assignment_02Source(String title){

super(title);

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

JPanel cp=(JPanel)getContentPane();

[url removed, login to view](new Font("TimesRoman",[url removed, login to view],24));

[url removed, login to view](40,10,300,50);

[url removed, login to view](30,250,80,25);

[url removed, login to view](150,250,80,25);

[url removed, login to view](270,250,80,25);

[url removed, login to view](10,80,80,25);

[url removed, login to view](10,110,80,25);

[url removed, login to view](10,140,80,25);

[url removed, login to view](10,170,80,25);

[url removed, login to view](10,200,80,25);

[url removed, login to view](120,80,250,25);

[url removed, login to view](120,110,250,25);

[url removed, login to view](120,140,250,25);

[url removed, login to view](120,170,250,25);

[url removed, login to view](120,200,250,25);

[url removed, login to view](null);

[url removed, login to view](labelHeader);

[url removed, login to view](buttonPrev);

[url removed, login to view](buttonReset);

[url removed, login to view](buttonNext);

[url removed, login to view](labelName);

[url removed, login to view](textFieldName);

[url removed, login to view](labelAddress);

[url removed, login to view](textFieldAddress);

[url removed, login to view](labelCity);

[url removed, login to view](textFieldCity);

[url removed, login to view](labelState);

[url removed, login to view](textFieldState);

[url removed, login to view](labelZip);

[url removed, login to view](textFieldZip);

addWindowListener(new [url removed, login to view]() {

public void windowClosing([url removed, login to view] evt) {

shutDown();

}

});

[url removed, login to view](new [url removed, login to view]() {

public void actionPerformed([url removed, login to view] evt) {

if(arrayPointer > 0){

--arrayPointer;

}

setFields(arrayPointer);

}

});

}

private void setFields(int position){

[url removed, login to view](DataClassArray[position].getName());

[url removed, login to view](DataClassArray[position].getAddress());

[url removed, login to view](DataClassArray[position].getCity());

[url removed, login to view](DataClassArray[position].getState());

[url removed, login to view](DataClassArray[position].getZip());

}

private void shutDown(){

int returnVal=[url removed, login to view](this, "Are you sure you want to quit?");

if(returnVal==JOptionPane.YES_OPTION){

[url removed, login to view](0);

}

}

public static void main(String args[]){

Assignment_02Source a2 = new Assignment_02Source("Database Browser");

[url removed, login to view](400,350);

[url removed, login to view](true);

}

}

class DataClass{

// To save space I declared all String objects on a single line

String name, address, city, state, zipCode;

DataClass(String name, String address, String city, String state, String zipCode){

[url removed, login to view] = name;

[url removed, login to view] = address;

[url removed, login to view] = city;

[url removed, login to view] = state;

[url removed, login to view] = zipCode;

}

// To save space I placed the methods on a single line

String getName(){return [url removed, login to view];}

String getAddress(){return [url removed, login to view];}

String getCity(){return [url removed, login to view];}

String getState(){return [url removed, login to view];}

String getZip(){return [url removed, login to view];}

}

Taidot: Java

Näytä lisää: assignment_02source extends jframe, johnson and johnson, first class objects in java, at johnson, display elements array onto buttons gui java, java array string button settext, java setbounds position button, display array values java gui, jtextfield array, show data jtextfields database, display arrays gui java, java previous next buttons array, java next button array, java swing reset string array elements, javahelp button, java moving jtextfield data array, display next array button java, update last element array java example, setbounds java help, cpadd java, java gui update array data, moving help center, VOID, update java code, thomas

About the Employer:
( 26 reviews ) Nebraska, United States

Projektin tunnus: #406020