我有一个问题是JLabel使用类中的方法设置一个文本,从一个不同的类调用该方法创建GUI.设置的方法JLabel在GUI外部调用,但是当从GUI类内部调用时,它可以工作.getText()从GUI类外部调用后,我在标签上测试了该方法,并显示标签已更新.我知道它可能是Swing的油漆问题或更新问题,但我不知道该怎么做.我已经尝试repaint()并revalidate()在标签上,然后面板,它在内.这是我目前的代码:
public void setStatusLabel(String statusEntered) {
//Shows the variable statusEntered has been received
System.out.println(statusEntered);
//Not working
status_label.setText(statusEntered);
//Used this to check if the label receives the data. It does.
String status = status_label.getText();
System.out.println(status);
}
Run Code Online (Sandbox Code Playgroud)
以及我称之为的背景.设置数据库连接
//GUI Class reference
MainWindow mainwindow = new MainWindow();
public void connect(){
Connection conn = null;
try {
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost:3306";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, …Run Code Online (Sandbox Code Playgroud) 我是一个偏执型的人,即使我mysql_close()在做了一些事情之后包含在我的PHP函数中,是否有一种方法可以检查(除了另一个查询)以查看连接是否仍然是打开的,只是为了保证.
我有一个应用程序的一部分,以Array的形式循环返回MySQL查询(我们都知道).但是,我需要在返回的某些项目上放置几种不同的格式设置,例如,一列需要日元货币,另一列需要美国货币,其中一个返回的项目是图像的链接.
我会使用列的名称,但是我用来完成此功能的相同功能将用于许多不同的表.
到目前为止,这就是我对循环的看法.
while($row = mysql_fetch_array($result)) {
for($i=0;$i<=count($row);$i++) {
if($row[i]==$row['Yen_Price']) {// I didn't expect this to work...but this is what I would like to do.
echo "Hello";
}
echo "<td>" . $row[$i] . "</td>";
}
}
Run Code Online (Sandbox Code Playgroud) 也许我会以错误的方式解决这个问题.让我知道使用Swing和AWT,我在一个框架上设置了几个按钮,它们每个都有一个ActionListener对应于它们的特定功能IE
JButton foo_button = new JButton("Foo-Me");
foo_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//Fancy schmancy code work
}
})
JButton bar_button = new JButton("Bar None");
bar_button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//Fancy schmancy code work
}
})
Run Code Online (Sandbox Code Playgroud)
所以每个按钮都做自己的事情.但是,如果我希望所有按钮都做某件事(每个按钮的方法相同),在我的情况下,清除标签,然后再做他们自己的事情.
显然我可以将whatever_label.setText("")添加到每个actionPerformed(),但这需要大量的重复,我不是那么喜欢的东西.
哦Java和Swing大师来帮助我.
我有用户可以添加日期范围,以及价格的页面.默认情况下有三个,但用户可以使用添加日期范围按钮按钮添加更多范围.我的问题是,在我获得$_POST值后添加一些额外的日期范围后,它没有显示附加的html元素的帖子值.
javascript部分
var n = 0;
$(document).ready(function () {
$("#btn2").click(function () {
$("#add_drange").append(" <p><input type='text' name='from" + n + "' class='datepicker' placeholder='From' /> <input type='text' name='to" + n + "' class='datepicker' placeholder='To' /> <input type='text' name='price" + n + "'id='price' placeholder='Price in USD' /></p>");
n = n + $("#add_drange").length;
//c = c + n;
//alert(n);
if (n == 25) {
alert('You can only add 25 Date Ranges');
event.preventDefault();
$("#btn2").hide();
}
$(".datepicker").datepicker({
dateFormat: 'yy-mm-dd'
}).val();
});
});
Run Code Online (Sandbox Code Playgroud)
HTML
<div id="add_drange">
<br> …Run Code Online (Sandbox Code Playgroud) 我看了,找不到我的问题的简单答案.我点击其中一个,TR然后点击另一个TR,它工作正常,但在点击两个后,它不再识别点击一行.有帮助吗?这是HTML:
<table>
<th>1</th>
<th>2</th>
<tr>
<td>Yes
<input type='radio' name='test' value='yes' />
</td>
</tr>
<tr>
<td>No
<input type='radio' name='test' value='no' />
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这是jquery
$(function () {
$('table tr').click(function () {
$(this).find('input:radio').attr('checked', 'checked');
});
});
Run Code Online (Sandbox Code Playgroud) 所以我希望能够从MySQL获取信息.在我的PHP代码中,我调用查询并以这种方式回显信息:
$sql = "SELECT * FROM `person`";
$rs = $COMMON->executeQuery($sql, $_SERVER["SCRIPT_NAME"]);
while($row = mysql_fetch_row($rs)){
echo ("Name: ".$row['name']."<br />";
echo ("Gender: ".$row['gender']."<br />";
echo ("Age: ".$row['age']."<br />";
};
Run Code Online (Sandbox Code Playgroud)
虽然,$row['name']其余的实际价值是完全空白的.甚至没有一个空间.虽然,当我通过实际列索引调用它时$row[1],它给了我正确的值.
所以,例如,假设这个表中有三个人.最终结果页面如下所示:
Name:
Gender:
Age:
Name:
Gender:
Age:
Name:
Gender:
Age:
Run Code Online (Sandbox Code Playgroud)
我做错了吗?为什么它给我这个空字符串而不是查询值?
MySQL数据库保存在MyPHPAdmin上.我不知道它是否有所作为.如果您认为缺少任何信息,请告诉我.谢谢!
如何获得一个Unicode string使用时request.querystring['param']
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace DataAnalysis
{
class Data
{
public int InTime;
public string InLocation;
public bool Direction;
public int LOS_F;
// create a Data object from a CSV format string.
static Data FromString(string line)
{
var fields = line.split(",");
return new Data
{
InTime = TimeSpan.Parse(fields[3]),
InLocation = fields[5],
Direction = fields[5][0], // to get the direction E/N/S/W
LOS_F = float.Parse(fields[16])
};
}
}
class Program
{
string[] directions …Run Code Online (Sandbox Code Playgroud) 我的查询:
$query=mysql_query("select * from people order by birth asc");
while($r=mysql_fetch_assoc($query)){
$birth=$r['birth'];
if($r['addmonth']=="2") {
$birth=date("d-m-Y", strtotime("$birth+2 month")); //additional months on date of birth
}
echo"$r[name] $birth";
}
Run Code Online (Sandbox Code Playgroud)
如何用$ birth ASC返回的php排序
package Game;
import java.util.Scanner;
public class practice {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String jack = "good, how are you?";
System.out.println("Hello, my name is Julie the Robot");
try{
Thread.sleep(1000);
}catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
System.out.println("How Are You?");
if (jack.equals(sc.nextLine())); {
System.out.println("Im Doing Great!");
}
// this code is giving me an error
else if (!jack.equals(sc.nextLine()));{
System.out.println("Oh! So you dont care about me eh?");
}
try{
Thread.sleep(700);
}catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
System.out.print("...");
try{
Thread.sleep(200); …Run Code Online (Sandbox Code Playgroud)