gpt4 book ai didi

java - 为操作监听器提供字符串质量并在 if 语句中使用这些字符串

转载 作者:行者123 更新时间:2023-11-30 03:20:38 25 4
gpt4 key购买 nike

作为一种自学 Action 监听器、按钮和 Jframe 的副项目,我开始使用一些基于电视节目等的分析器。按钮和 Action 监听器可以工作,但我只是不知道如何为 Action 监听器提供字符串并调用这些字符串。我哪里错了?预先感谢您。

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class ProfileCreatorWithoutRecords extends JFrame {

public static void main(String[] args) throws IOException {
final String dramaAnswer;
final String comedyStyleAnswer;
final String comedyShowAnswer;

final JFrame fridayFrame = new JFrame();
fridayFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://s21.postimg.org/xfdlwcr2f/friday_night_lights_season_4_pictures.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 500, 350, this);
}
});
final JButton fridayButton = new JButton("Friday Night Lights");
fridayFrame.add(fridayButton);
fridayFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
fridayFrame.setSize(500, 350);
fridayFrame.setVisible(true);
fridayFrame.setLocation(0, 0);

///////////////////////////////////////////////////////////////////MAD MEN
final JFrame madFrame = new JFrame();
madFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://s27.postimg.org/c1lxi135v/mad_men_1024x768.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 1024, 768, this);
}
});

final JButton madButton = new JButton("Mad Men");
madFrame.add(madButton);
madFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
madFrame.setSize(1024, 768);
madFrame.setVisible(true);
madFrame.setLocation(900,0);

////////////////////////////////////////HOUSE OF CARDS
final JFrame houseFrame = new JFrame();
houseFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://cdn.bgr.com/2013/04/netflix-house-of-cards.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 620, 458, this);
}
});
final JButton houseButton = new JButton("House of Cards");
houseFrame.setVisible(true);
houseFrame.setSize(620, 458);
houseFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
houseFrame.add(houseButton);
houseFrame.setLocation(0, 400);

//////////////////////////////////////////////////////////////////////////////////GAFFIGAN
final JFrame gaffiganFrame = new JFrame();
gaffiganFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://thepost.s3.amazonaws.com/wp-content/uploads/2015/02/Jim-Gaffigan-Wilbur-Artist1.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 550, 253, this);
}
});
final JButton gaffiganButton = new JButton("Clean comedy");
gaffiganFrame.setVisible(false);
gaffiganFrame.setSize(550, 253);
gaffiganFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
gaffiganFrame.add(gaffiganButton);
gaffiganFrame.setLocation(0, 0);

///////////////////////////////////////////////////////////////////////////////////LOUIE
final JFrame louieFrame = new JFrame();
louieFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://static.dudeiwantthat.com/omg/video-clips/Louis-CK-Live-at-the-Beacon-Theater-1604.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 504, 420, this);
}
});
final JButton louieButton = new JButton("Dirty, rant comedy");
louieFrame.setVisible(false);
louieFrame.setSize(504, 420);
louieFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
louieFrame.add(louieButton);
louieFrame.setLocation(500, 0);

final JFrame officeFrame = new JFrame();
officeFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("https://sarahsayswatchit.files.wordpress.com/2011/05/the-office.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 600, 600, this);
}
});
final JButton officeButton = new JButton("The Office");
officeFrame.setVisible(false);
officeFrame.setSize(600, 600);
officeFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
officeFrame.add(officeButton);
officeFrame.setLocation(0, 0);

final JFrame southFrame = new JFrame();
southFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://2.images.southparkstudios.com/default/image.jpg?quality=0.8"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 480, 360, this);
}
});
final JButton southButton = new JButton("South Park");
southFrame.setVisible(false);
southFrame.setSize(480, 360);
southFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
southFrame.add(southButton);
southFrame.setLocation(650, 0);

final JFrame bigbangFrame = new JFrame();
bigbangFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://1.bp.blogspot.com/-w8v5FzJwAdk/U_NlRh73i5I/AAAAAAAABsU/02yuF3IPs78/s1600/the-big-bang-theory%3DSatanismo.png"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 1000, 562, this);
}
});
final JButton bigbangButton = new JButton("Big Boob Blonde Lady");
bigbangFrame.setVisible(false);
bigbangFrame.setSize(1000, 562);
bigbangFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
bigbangFrame.add(bigbangButton);
bigbangFrame.setLocation(0, 800);

fridayButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent fridayclicked) {
String dramaAnswer = "fridaynightlights";
fridayFrame.setVisible(false);
madFrame.setVisible(false);
houseFrame.setVisible(false);
gaffiganFrame.setVisible(true);
louieFrame.setVisible(true);
}
});

madButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent madclicked) {
dramaAnswer = "madmen";
madFrame.setVisible(false);
fridayFrame.setVisible(false);
houseFrame.setVisible(false);
gaffiganFrame.setVisible(true);
louieFrame.setVisible(true);
}
});

houseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent houseclicked) {
dramaAnswer = "houseofcards";
fridayFrame.setVisible(false);
houseFrame.setVisible(false);
madFrame.setVisible(false);
louieFrame.setVisible(true);
gaffiganFrame.setVisible(true);
}

});

gaffiganButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent cleanpicked) {
comedyStyleAnswer = "CleanComedy";
louieFrame.setVisible(false);
gaffiganFrame.setVisible(false);
officeFrame.setVisible(true);
southFrame.setVisible(true);
bigbangFrame.setVisible(true);
}

});
louieButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent dirtypicked) {
comedyStyleAnswer = "DirtyComedy";
louieFrame.setVisible(false);
gaffiganFrame.setVisible(false);
officeFrame.setVisible(true);
southFrame.setVisible(true);
bigbangFrame.setVisible(true);
}
});
officeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent officepicked) {
comedyShowAnswer = "Office";
officeFrame.setVisible(false);
southFrame.setVisible(false);
bigbangFrame.setVisible(false);
}

});
southButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent southpark) {
comedyShowAnswer = "southpark";
officeFrame.setVisible(false);
southFrame.setVisible(false);
bigbangFrame.setVisible(false);
}

});
bigbangButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent bigbang) {
comedyShowAnswer = "bigbang";
officeFrame.setVisible(false);
southFrame.setVisible(false);
bigbangFrame.setVisible(false);
}
});
}

giveReccomendation(dramaAnswer, comedyStyleAnswer, comedyShowAnswer);
}

public static void giveReccomendation (String dramaAnswer, String comedyStyleAnswer, String comedyShowAnswer) throws IOException {
System.out.println("public static void started");
JFrame personFrame = new JFrame();
personFrame.setContentPane(new JPanel() {
BufferedImage image = ImageIO.read(new URL("http://images.vcpost.com/data/images/full/29158/person-of-interest-on-cbs.jpg"));
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 1000, 650, this);
}
});
JLabel personLabel = new JLabel("Person Of Interest");
personFrame.add(personLabel);
personFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
personFrame.setSize(1000, 650);
personFrame.setVisible(false);
personFrame.setLocation(0, 0);
System.out.println("person frame created");

if (dramaAnswer.equalsIgnoreCase("fridaynightlights")
&& comedyStyleAnswer.equalsIgnoreCase("clean")
&& comedyShowAnswer.equalsIgnoreCase("office")) {
personFrame.setVisible(true);
System.out.println("person frame set visible");
}
}

}

最佳答案

因为您将唯一的调用放在主线程中,所以您所做的就是在框架和所有监听器设置完毕后调用 GiveRecommendation 方法。

虽然您的操作监听器将正确设置本地字符串的值,但它们不会执行其他操作。

因此,如果您想调用 GiveRecommendation 方法,请将其放置在现有的操作监听器之一中,或者创建一个新的按钮和操作监听器。

关于java - 为操作监听器提供字符串质量并在 if 语句中使用这些字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31417654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com