J#和C#有什么区别?(What is the difference between J# and C#)
我一直在阅读有关使用J#的人。
但我的问题是:J#和C#有什么区别?
好吧,我对J#的理解就像C#,但在Java中。 我是否正确? C#之前是J#吗?
我希望有人可以帮助我更好地理解这一点。
I have been reading around about people using J#.
But my question is: What is the difference between J# and C#?
OK, my understanding of J# is like C# but in Java. Am I correct in that? Was J# before C#?
I hope someone can help me understand this better.
原文:https://stackoverflow.com/questions/6599477
最满意答案
你必须编码帧的重新启动。 考虑开始时的游戏状态以及所有组件的状态。 通常你会在某个地方
setup
一个setup
点,并在某个阶段开始。 如果您可以设置这些,只需使用setup
并restart
。public void actionPerformed(ActionEvent e) { if (e.getSource() == restartBtn) { restart(); } } public void restart(){ stop(); // if necessary setup(); // set everything to initial state start(); // start game } public void stop(){ // stop any timers, threads, operations etc. } public void setup(){ // set to initial state. // something like recreate the deck, // clear hands and table, shuffle, and deal. } public void start(){ // code to initiate the game. }
所以最好的办法是把你的游戏看成几个阶段,像
restart
这样的动作应该是其他的组合。 在不了解你的实际游戏代码(或计划)的情况下,很难专门回答这个问题。 但我希望这有帮助。 :)编辑
这是关于生成/洗牌的更好方法。public class GenRandom { int [] cards = new int [GameFrame.NUMBER_OF_CARDS]; public void generateCards() { for (int i = 0; i < cards.length; i++) { // for each index of the array... int card; // declare card do { card = (int) (Math.random() * 51) + 1; // random between 1 and 52 } while (contains(card)); // regenerate random card if array already contains. cards[i] = card; // card is unique, so assign value to array index } } private boolean contains(int t){ for(int i = 0; i < GameFrame.NUMBER_OF_CARDS; i++){ // for each index... if(cards[i] == t){ return true; // if the generated card is already in the array.. } } return false; // otherwise reached end, so return false. } public int [] getAllCards() { return cards; } }
You'll have to code the restart of the frame. Consider the state of the game at the start and what all the components' states are. Generally you'd have a
setup
point somewhere andstart
as well at some stage. If you can set those up it would be easy to just usesetup
andstart
asrestart
.public void actionPerformed(ActionEvent e) { if (e.getSource() == restartBtn) { restart(); } } public void restart(){ stop(); // if necessary setup(); // set everything to initial state start(); // start game } public void stop(){ // stop any timers, threads, operations etc. } public void setup(){ // set to initial state. // something like recreate the deck, // clear hands and table, shuffle, and deal. } public void start(){ // code to initiate the game. }
So the best way to go about it is to see your game as several stages, and actions such as
restart
should be a combination of others. Without knowing anything about your actual game code (or plans for it), it's difficult to answer this specifically. But I hope that helps. :)EDIT
This is a better way of going about generating / shuffling cards.public class GenRandom { int [] cards = new int [GameFrame.NUMBER_OF_CARDS]; public void generateCards() { for (int i = 0; i < cards.length; i++) { // for each index of the array... int card; // declare card do { card = (int) (Math.random() * 51) + 1; // random between 1 and 52 } while (contains(card)); // regenerate random card if array already contains. cards[i] = card; // card is unique, so assign value to array index } } private boolean contains(int t){ for(int i = 0; i < GameFrame.NUMBER_OF_CARDS; i++){ // for each index... if(cards[i] == t){ return true; // if the generated card is already in the array.. } } return false; // otherwise reached end, so return false. } public int [] getAllCards() { return cards; } }
相关问答
更多-
一种简单的方法是为JPanel类提供一个委托方法,允许其他类将ActionListeners添加到感兴趣的按钮。 例如: public void addButton1ActionListener(ActionListener listener) { button1.addActionListener(listener); } 这样,如果JFrame包含JPanel的实例,它可以调用此方法将侦听器传递给JButton。 例如: import java.awt.BorderLayout; import ...
-
您可能可以修改此基于Swing的Launcher ,它使用ProcessBuilder在独立的JVM中运行程序。 package gui; import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.BorderFac ...
-
JFrame所依赖的Window类具有getOwner()方法,该方法将返回任何子窗口的“所有者”窗口。 但话虽如此,子窗口应该是JDialogs, 而不是 JFrames,因为您的应用程序应该只有一个JFrame,我相信JFrames没有所有者,所以这个方法可能返回null。 如果需要更改JFrame中的“视图”,请使用CardLayout,如果需要显示子窗口,请使用JDialogs和JOptionPanes等对话框窗口。 请阅读: 使用多个JFrame,好/坏的做法? ,有关这方面的更多信息。 但话虽如 ...
-
你必须编码帧的重新启动。 考虑开始时的游戏状态以及所有组件的状态。 通常你会在某个地方setup一个setup点,并在某个阶段开始。 如果您可以设置这些,只需使用setup并restart 。 public void actionPerformed(ActionEvent e) { if (e.getSource() == restartBtn) { restart(); } } public void restart(){ stop(); // if nece ...
-
单击另一个Jframe中的按钮时弹出现有Jframe(Popup existing Jframe when clicking button in another Jframe)[2023-04-29]
button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new SecondFrame().setVisible(true); FirstFrame.this.dispose(); // if you want the first frame to close } 有关更多信息,请查看如何编写动作侦听器 ... -
单击按钮时,在JFrame中从另一个类添加JPanel(Adding JPanel from another class in JFrame When Button Clicked)[2024-01-30]
我想你想要展示 你所做的是你把所有的东西都添加到了你的addPanel但你忘了添加addsPanel本身。 import java.awt.*; import javax.swing.*; public class AddingWindow extends JPanel { AddingWindow() { JPanel addingPanel = new JPanel(); addingPanel.setLayout(new GridLayout(2, 2)); JLabel fullName ... -
尝试这个: JB[i].setText(nums[i]); 而不是这个: JB[i] = new JButton(nums[i]); 更改按钮文字。 不需要重启(我想这是你想要做的?) Try this: JB[i].setText(nums[i]); instead of this: JB[i] = new JButton(nums[i]); to change button text. No restart needed (I think this is what you're trying t ...
-
单击“提交”按钮时如何设置半透明的jframe?(how to set semi-transparent jframe when “submit” button is clicked?)[2021-07-18]
不幸的是我认为没有办法保持系统窗口的装饰,你可能不得不使用默认的。 由于我不是100%确定你是想要切换整个帧的不透明度还是只是框架的背景,我在我的例子中包含了这两个函数。 (如果你不想装饰,mKorbels会给你更多帮助) 码: import java.awt.Color; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.Actio ... -
单击按钮时如何使JFrame显示高级选项[关闭](How to make a JFrame show advanced options when a button is clicked [closed])[2023-07-07]
如果您想要做的就是根据按钮隐藏/显示一些挥杆对象,请按以下代码为您提供基本模板。 在initialize方法中创建所需的所有项目 - 但是将要操作的对象设置为您的类的私有对象。 我更喜欢让我的类实现actionlistener - 你可以为每个按钮设置一个唯一的actionlistener。 按下按钮可使按键上的项目可见按。 基本代码是: package expand; import java.awt.EventQueue; import java.awt.event.ActionEvent; impor ... -
假设你的按钮有一个actionListener,在点击“规则按钮”后输入: JFrame1.dispose(); //Remove JFrame 1 JFrame2.setVisible(true) //Show other frame 然后尊重他们反对的反应 Assuming your button has an actionListener, after clicking the "rules button" put in: JFrame1.dispose(); ...