diff --git a/.gitignore b/.gitignore index 7f59e8c..5bd5c42 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -twitter4j.properties \ No newline at end of file +twitter4j.properties +/Model/nbproject/private/ +/JavaTwitter/nbproject/private/ +/JavaTwitter/build/ +/build/ \ No newline at end of file diff --git a/JavaTwitter/build.xml b/JavaTwitter/build.xml new file mode 100644 index 0000000..4caa400 --- /dev/null +++ b/JavaTwitter/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project JavaTwitter. + + + diff --git a/JavaTwitter/manifest.mf b/JavaTwitter/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/JavaTwitter/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/JavaTwitter/nbproject/build-impl.xml b/JavaTwitter/nbproject/build-impl.xml new file mode 100644 index 0000000..1328999 --- /dev/null +++ b/JavaTwitter/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/JavaTwitter/nbproject/genfiles.properties b/JavaTwitter/nbproject/genfiles.properties new file mode 100644 index 0000000..6e3dbce --- /dev/null +++ b/JavaTwitter/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=705114bd +build.xml.script.CRC32=948b794e +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=705114bd +nbproject/build-impl.xml.script.CRC32=c7c99fae +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/JavaTwitter/nbproject/project.properties b/JavaTwitter/nbproject/project.properties new file mode 100644 index 0000000..fe0439b --- /dev/null +++ b/JavaTwitter/nbproject/project.properties @@ -0,0 +1,78 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/JavaTwitter.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.twitter4j-core-4.0.4.jar=F:\\Task_6\\Task_6\\twitter4j-core-4.0.4.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.twitter4j-core-4.0.4.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir}:\ + ${libs.junit_4.classpath}:\ + ${libs.hamcrest.classpath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=Driver.Driver +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/JavaTwitter/nbproject/project.xml b/JavaTwitter/nbproject/project.xml new file mode 100644 index 0000000..246057b --- /dev/null +++ b/JavaTwitter/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + JavaTwitter + + + + + + + + + diff --git a/JavaTwitter/src/Controller/controller.java b/JavaTwitter/src/Controller/controller.java new file mode 100644 index 0000000..01c7399 --- /dev/null +++ b/JavaTwitter/src/Controller/controller.java @@ -0,0 +1,102 @@ + +package Controller; + +import GUI.ComposeTweet; +import GUI.FollowUser; +import GUI.HomeTimeline; +import Interface.View; +import Model.TwitterModel; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JOptionPane; + +/** + * + * @author Ihsan Fajri + */ +public class controller implements ActionListener { + private TwitterModel model; + private View view; + + public controller() { + model = new TwitterModel(); + goToHomeTimeline(); + } + + public void goToHomeTimeline() { + HomeTimeline home = new HomeTimeline(); + home.setVisible(true); + home.addListener(this); + home.setTimeline(model.getHomeTimeline()); + view = home; + } + + private void goToComposeTweet() { + ComposeTweet compose = new ComposeTweet(); + compose.setVisible(true); + compose.addListener(this); + view = compose; + } + + private void goToFollowUser() { + FollowUser follow = new FollowUser(); + follow.setVisible(true); + follow.addListener(this); + view = follow; + + } + + public void actionPerformed(ActionEvent ae) { + Object source = ae.getSource(); + try { + if (view instanceof HomeTimeline) { + HomeTimeline home = (HomeTimeline) view; + if (source.equals(home.getBtnCompose())) { + goToComposeTweet(); + home.dispose(); + + } else if (source.equals(home.getBtnFollow())) { + goToFollowUser(); + home.dispose(); + + } else if (source.equals(home.getBtnRefresh())) { + String timeline = model.getHomeTimeline(); + home.setTimeline(timeline); + + } else if (source.equals(home.getBtnExit())) { + JOptionPane.showMessageDialog(null, "Thank You"); + System.exit(0); + } + } else if (view instanceof ComposeTweet){ + + ComposeTweet compose = (ComposeTweet) view; + if (source.equals(compose.getBtnCancel())) { + goToHomeTimeline(); + compose.dispose(); + + } else if (source.equals(compose.getBtnTweet())) { + String tweet = compose.getTweet(); + model.tweetStatus(tweet); + goToHomeTimeline(); + compose.dispose(); + } + } else { + + FollowUser follow = (FollowUser) view; + if (source.equals(follow.getBtnCancel())) { + goToHomeTimeline(); + follow.dispose(); + } else if (source.equals(follow.getBtnFollow())) { + String user = follow.getUser(); + model.followUser(user); + follow.setUser(""); + } + } + + + }catch (Exception e) { + JOptionPane.showMessageDialog((Component) view, e.getMessage()); + } + } +} diff --git a/JavaTwitter/src/Driver/Driver.java b/JavaTwitter/src/Driver/Driver.java new file mode 100644 index 0000000..d3d6ce6 --- /dev/null +++ b/JavaTwitter/src/Driver/Driver.java @@ -0,0 +1,13 @@ +package Driver; + +/** + * + * @author Ihsan Fajri + */ +import Controller.controller; + +public class Driver { + public static void main (String[] args) { + controller c = new controller(); + } +} diff --git a/JavaTwitter/src/GUI/ComposeTweet.form b/JavaTwitter/src/GUI/ComposeTweet.form new file mode 100644 index 0000000..7456619 --- /dev/null +++ b/JavaTwitter/src/GUI/ComposeTweet.form @@ -0,0 +1,106 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/JavaTwitter/src/GUI/ComposeTweet.java b/JavaTwitter/src/GUI/ComposeTweet.java new file mode 100644 index 0000000..dcd122c --- /dev/null +++ b/JavaTwitter/src/GUI/ComposeTweet.java @@ -0,0 +1,118 @@ + +package GUI; + +import Interface.View; +import java.awt.event.ActionListener; + +/** + * + * @author Ihsan Fajri + */ +public class ComposeTweet extends javax.swing.JFrame implements View{ + + public ComposeTweet() { + initComponents(); + } + + + public Object getBtnCancel () { + return btnCancel; + } + + public Object getBtnTweet () { + return btnTweet; + } + + public String getTweet () { + return txAreaTweet.getText (); + } + + public void addListener (ActionListener e) { + btnCancel.addActionListener(e); + btnTweet.addActionListener(e); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + txAreaTweet = new javax.swing.JTextArea(); + jLabel1 = new javax.swing.JLabel(); + btnTweet = new javax.swing.JButton(); + btnCancel = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + txAreaTweet.setColumns(20); + txAreaTweet.setRows(5); + jScrollPane1.setViewportView(txAreaTweet); + + jLabel1.setText("Compose new Tweet...."); + + btnTweet.setText("Tweet"); + + btnCancel.setText("Cancel"); + btnCancel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnCancelActionPerformed(evt); + } + }); + + jLabel2.setText("140"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel1)) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btnCancel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnTweet))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addGap(13, 13, 13) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnTweet) + .addComponent(btnCancel) + .addComponent(jLabel2)) + .addContainerGap(19, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_btnCancelActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnCancel; + private javax.swing.JButton btnTweet; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea txAreaTweet; + // End of variables declaration//GEN-END:variables + + +} diff --git a/JavaTwitter/src/GUI/FollowUser.form b/JavaTwitter/src/GUI/FollowUser.form new file mode 100644 index 0000000..361dafe --- /dev/null +++ b/JavaTwitter/src/GUI/FollowUser.form @@ -0,0 +1,90 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/JavaTwitter/src/GUI/FollowUser.java b/JavaTwitter/src/GUI/FollowUser.java new file mode 100644 index 0000000..5649889 --- /dev/null +++ b/JavaTwitter/src/GUI/FollowUser.java @@ -0,0 +1,111 @@ +package GUI; + +import Interface.View; +import java.awt.event.ActionListener; + +/** + * + * @author Ihsan Fajri + */ +public class FollowUser extends javax.swing.JFrame implements View { + + public FollowUser() { + initComponents(); + } + + public Object getBtnCancel () { + return btnCancel; + } + + public Object getBtnFollow () { + return btnFollow; + } + + public String getUser () { + return txFieldUser.getText (); + } + + public void setUser (String s) { + txFieldUser.setText (s); + } + + public void addListener (ActionListener e) { + btnCancel.addActionListener(e); + btnFollow.addActionListener(e); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + txFieldUser = new javax.swing.JTextField(); + btnCancel = new javax.swing.JButton(); + btnFollow = new javax.swing.JButton(); + jLabel1 = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + txFieldUser.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + txFieldUserActionPerformed(evt); + } + }); + + btnCancel.setText("Cancel"); + + btnFollow.setText("Follow"); + + jLabel1.setText("Follow User"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(txFieldUser, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(btnCancel) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btnFollow))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel1) + .addGap(16, 16, 16) + .addComponent(txFieldUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnFollow) + .addComponent(btnCancel)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void txFieldUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txFieldUserActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_txFieldUserActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnCancel; + private javax.swing.JButton btnFollow; + private javax.swing.JLabel jLabel1; + private javax.swing.JTextField txFieldUser; + // End of variables declaration//GEN-END:variables + + +} diff --git a/JavaTwitter/src/GUI/HomeTimeline.form b/JavaTwitter/src/GUI/HomeTimeline.form new file mode 100644 index 0000000..bb26d25 --- /dev/null +++ b/JavaTwitter/src/GUI/HomeTimeline.form @@ -0,0 +1,105 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/JavaTwitter/src/GUI/HomeTimeline.java b/JavaTwitter/src/GUI/HomeTimeline.java new file mode 100644 index 0000000..7102904 --- /dev/null +++ b/JavaTwitter/src/GUI/HomeTimeline.java @@ -0,0 +1,129 @@ +package GUI; + + +import Interface.View; +import java.awt.event.ActionListener; + +/** + * + * @author Ihsan Fajri + */ +public class HomeTimeline extends javax.swing.JFrame implements View { + + + public HomeTimeline() { + initComponents(); + } + + public Object getBtnCompose () { + return btnCompose; + } + + public Object getBtnExit () { + return btnExit; + } + + public Object getBtnFollow () { + return btnFollow; + } + + public Object getBtnRefresh () { + return btnRefresh; + } + + public void setTimeline (String s) { + txAreaTimeline.setText(s); + } + + public void addListener (ActionListener e) { + btnCompose.addActionListener(e); + btnExit.addActionListener(e); + btnFollow.addActionListener(e); + btnRefresh.addActionListener(e); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane1 = new javax.swing.JScrollPane(); + txAreaTimeline = new javax.swing.JTextArea(); + btnCompose = new javax.swing.JButton(); + btnFollow = new javax.swing.JButton(); + btnRefresh = new javax.swing.JButton(); + btnExit = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + + jScrollPane1.setOpaque(false); + + txAreaTimeline.setEditable(false); + txAreaTimeline.setColumns(20); + txAreaTimeline.setRows(5); + jScrollPane1.setViewportView(txAreaTimeline); + + btnCompose.setText("Compose"); + + btnFollow.setText("Follow User"); + btnFollow.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnFollowActionPerformed(evt); + } + }); + + btnRefresh.setText("Refresh"); + + btnExit.setText("Exit"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1) + .addGroup(layout.createSequentialGroup() + .addComponent(btnCompose) + .addGap(18, 18, 18) + .addComponent(btnFollow) + .addGap(18, 18, 18) + .addComponent(btnRefresh) + .addGap(18, 18, 18) + .addComponent(btnExit, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnCompose) + .addComponent(btnFollow) + .addComponent(btnRefresh) + .addComponent(btnExit)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void btnFollowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFollowActionPerformed + + }//GEN-LAST:event_btnFollowActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnCompose; + private javax.swing.JButton btnExit; + private javax.swing.JButton btnFollow; + private javax.swing.JButton btnRefresh; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JTextArea txAreaTimeline; + // End of variables declaration//GEN-END:variables + + + + +} diff --git a/JavaTwitter/src/Interface/View.java b/JavaTwitter/src/Interface/View.java new file mode 100644 index 0000000..87844cd --- /dev/null +++ b/JavaTwitter/src/Interface/View.java @@ -0,0 +1,12 @@ + +package Interface; + +import java.awt.event.ActionListener; + +/** + * + * @author Ihsan Fajri + */ +public interface View { + public void addListener(ActionListener e); +} diff --git a/JavaTwitter/src/Model/TwitterModel.java b/JavaTwitter/src/Model/TwitterModel.java new file mode 100644 index 0000000..e96df3e --- /dev/null +++ b/JavaTwitter/src/Model/TwitterModel.java @@ -0,0 +1,53 @@ +package Model; + +import twitter4j.*; +import java.util.List; +import javax.swing.JOptionPane; + + +/** + * + * @author Ihsan Fajri + */ +public class TwitterModel { + private Twitter twitter; + + public TwitterModel(){ + twitter = new TwitterFactory().getInstance(); + } + + public void tweetStatus (String tweet) { + try { + twitter.updateStatus(tweet); + JOptionPane.showMessageDialog(null, "Pesan Berhasil"); + } catch (Exception e) { + JOptionPane.showMessageDialog (null, "Judul Exception" , "Pesan exception", JOptionPane.ERROR_MESSAGE); + } + + } + + public String getHomeTimeline () { + try { + String s = " "; + List status = twitter.getHomeTimeline (); + for (int i = 0; i < status.size (); i++) { + s = s+ status.get(i).getUser().getScreenName()+ " - " + + status.get (i).getText ()+ "\n\n"; + } + return s; + }catch (Exception e) { + JOptionPane.showMessageDialog (null, "Judul Exception", "Pesan Exception", JOptionPane.ERROR_MESSAGE); + } + return null; + } + + public void followUser (String user) { + try { + twitter.createFriendship(user); + }catch (Exception e) { + JOptionPane.showMessageDialog (null, "Judul Exception", "Pesan Exception", JOptionPane.ERROR_MESSAGE); + } + } + + +} diff --git a/JavaTwitter/test/GUI/HomeTimelineTest.java b/JavaTwitter/test/GUI/HomeTimelineTest.java new file mode 100644 index 0000000..fc0ef50 --- /dev/null +++ b/JavaTwitter/test/GUI/HomeTimelineTest.java @@ -0,0 +1,136 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package GUI; + +import java.awt.event.ActionListener; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Ihsan Fajri + */ +public class HomeTimelineTest { + + public HomeTimelineTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getBtnCompose method, of class HomeTimeline. + */ + @Test + public void testGetBtnCompose() { + System.out.println("getBtnCompose"); + HomeTimeline instance = new HomeTimeline(); + Object expResult = null; + Object result = instance.getBtnCompose(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getBtnExit method, of class HomeTimeline. + */ + @Test + public void testGetBtnExit() { + System.out.println("getBtnExit"); + HomeTimeline instance = new HomeTimeline(); + Object expResult = null; + Object result = instance.getBtnExit(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getBtnFollow method, of class HomeTimeline. + */ + @Test + public void testGetBtnFollow() { + System.out.println("getBtnFollow"); + HomeTimeline instance = new HomeTimeline(); + Object expResult = null; + Object result = instance.getBtnFollow(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getBtnRefresh method, of class HomeTimeline. + */ + @Test + public void testGetBtnRefresh() { + System.out.println("getBtnRefresh"); + HomeTimeline instance = new HomeTimeline(); + Object expResult = null; + Object result = instance.getBtnRefresh(); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of setTimeline method, of class HomeTimeline. + */ + @Test + public void testSetTimeline() { + System.out.println("setTimeline"); + String s = ""; + HomeTimeline instance = new HomeTimeline(); + instance.setTimeline(s); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of addListener method, of class HomeTimeline. + */ + @Test + public void testAddListener() { + System.out.println("addListener"); + ActionListener e = null; + HomeTimeline instance = new HomeTimeline(); + instance.addListener(e); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of setVisible method, of class HomeTimeline. + */ + @Test + public void testSetVisible() { + System.out.println("setVisible"); + boolean b = false; + HomeTimeline instance = new HomeTimeline(); + instance.setVisible(b); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + +} diff --git a/JavaTwitter/twitter4j-core-4.0.4-javadoc.jar b/JavaTwitter/twitter4j-core-4.0.4-javadoc.jar new file mode 100644 index 0000000..0123e83 Binary files /dev/null and b/JavaTwitter/twitter4j-core-4.0.4-javadoc.jar differ diff --git a/JavaTwitter/twitter4j.properties.txt b/JavaTwitter/twitter4j.properties.txt new file mode 100644 index 0000000..71e0ed6 --- /dev/null +++ b/JavaTwitter/twitter4j.properties.txt @@ -0,0 +1,5 @@ +debug=true +oauth.consumerKey=C2oLX3g4tQPZFyOG3UkiUoWll +oauth.consumerSecret=McL68Kg4948QCW3ZBHXPE2yu2Q3tk1k8MFxunWTFe2elnI7EQ7 +oauth.accessToken=163787615-EvGsvEqZ6xnVZqXOGsN6ET6W7MIlQrZyR6GAPFTk +oauth.accessTokenSecret=s3wINRxOibNBdidqsGdI2dOnQU1GTyFSopBPlyXauJ2KE \ No newline at end of file