model view controller - MVC Pattern GUI Program java (Updating GUI) -


hi guys i'm working on java programs , have been stuck hours trying figure out. hoping you's can me out i'm finding gui part difficult. asked following: create class called hobby, has attributes, hobbyname , constructor hobby object, accepts string name parameter.create class called hobbylist, holds vector or array of 10 hobbies (these 2 classes represent data (or model) in system). add addhobby (adds hobby vector) , gethobby (returns vector of hobbies) methods hobbylist class. create 2 view classes, call 1 view class listview (use jlist gui display hobbies held in hobbylist) , call other class comboview class (use jcombobox).in each gui provide way add hobbylist , button refresh list display. keep listener class(es) separate gui classes (the listener class\classes will
represent controller\controllers).

    public class hobby {      string hobbyname;      public hobby(string hobby)     {         this.hobbyname = hobby;      } } 

hobbylist class far

mport java.util.arraylist;    public class hobbylist {        public static void main(string[] args) {         hobbies.add("basketball");         hobbies.add("football");   }     static arraylist<string> hobbies = new arraylist<string>();     public void addhobby()     {         string hobby = "";         hobbies.add(hobby);      }      public arraylist<string> gethobby()     {         return hobbies;     } } 

listview class far

import javax.swing.*; import java.awt.*; import javax.swing.event.*; import java.awt.event.*;  class listview extends jframe  {     public static void main (string [] args)     {     jframe frame = new jframe("list view");        frame.setvisible(true);        frame.setsize(300,400);          jbutton button = new jbutton();        button.settext("add");        jlist hobbievalues = new jlist(hobbies); //not working          jpanel listpanel = new jpanel();        listpanel.add(button); //add button panel        listpanel.add(hobbievalues);       frame.add(listpanel); //add panel frame  } } 

i think should change line

jlist hobbievalues = new jlist(hobbies); 

to

jlist hobbievalues = new jlist(hobbylist.hobbies); 

although think jlist accepts vector or array argument. in case, can change following to

jlist hobbievalues = new jlist(hobbylist.hobbies.toarray()); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -