我去了一个小项目,但卡住了。使用java swing时,我无法添加标签(JLabel)。代码是这样的:
JFrame frm = new JFrame("frame");
JLabel label = new JLabel("test text");
frm.add(label);
执行此操作时出错。当我把光标放在它上面时,eclipse建议我配置构建路径。 我再次可以在netbeans中运行完全相同的代码。我该如何解决?
答案 0 :(得分:0)
<?php
$MERCHANT_KEY = "gtKFFx";
$hash_string = '';
$SALT = "eCwWELxi";
$PAYU_BASE_URL = "https://test.payu.in";
$action = '';
$posted = array();if(!empty($_POST)) { //print_r($_POST);
foreach($_POST as $key => $value) {
$posted[$key] = $value; }}
$formError = 0;
if(empty($posted['txnid']))
{
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);} else { $txnid = $posted['txnid'];}
$hash = '';
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
if( empty($posted['key'])
|| empty($posted['txnid'])
|| empty($posted['amount'])
|| empty($posted['firstname'])
|| empty($posted['email'])
|| empty($posted['phone'])
|| empty($posted['productinfo'])
|| empty($posted['udf1']) ) {
$formError = 1; } else {
$hashVarsSeq = explode('|', $hashSequence);
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : ''; $hash_string .= '|'; }
$hash_string .= $SALT; $hash = strtolower(hash('sha512', $hash_string));
$action = $PAYU_BASE_URL . '/_payment'; }}
elseif(!empty($posted['hash'])) {
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';}
?>
<script>
var hash = '<?php echo $hash ?>';
function submitPayuForm() {
if(hash == '') {
return;
}
var payuForm = document.forms.payuForm;
payuForm.submit();
}
</script>
<body onload="submitPayuForm()">
<br/>
<?php if($formError) { ?>
<p style="color:red;margin-top: -120px;padding: 50px;display:none;">Please fill all mandatory fields.</p>
<?php } ?>
<div class="container">
<div class="col-md-4" id="main">
<form action="<?php echo $action; ?>" method="post" name="payuForm" enctype="multipart/form-data" id="pay" class="myform">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
<input type="hidden" name="surl" value="https://pay-square.com/rechargesuccess-php" />
<input type="hidden" name="furl" value="https://pay-square.com/rechargefailure-php" />
<div class="probod">
<ul class="nav nav-pills" id="navtab">
<li class="active" ><a href="http://pay-square.com/" data-toggle="tab">Mobile</a></li>
<li><a href="http://pay-square.com/dth" >DTH</a></li>
<li><a href="http://pay-square.com/datacard">Data Card</a></li>
</ul> <br> <p style="color:red;">(* All Fields are Mandatory)</p>
<label for="sel1">Mobile No:</label>
<input type="text" name="phone" class="form-control" value="<?php echo (empty($posted['phone'])) ? '' : $posted['phone']; ?>" Placeholder="Enter Your 10 digit number" required>
<label for="sel1">Select Operator:</label>
<select id="opt" class="form-control" title="" name="udf1" size="1">
<option value="">Select One</option>
<option value="28">Airtel</option>
<option value="1">Aircel</option>
</select>
<label for="sel1">Select Circle:</label>
<select id="cir" class="form-control" title="" name="cir" size="1">
<option value="">-Select Circle-</option>
<option value="23">Chennai </option>
<option value="1">Delhi NCR</option>
<option value="9">UP East</option>
<option value="11">UP West & Uttarakhand</option>
<option value="12">West Bengal</option>
</select>
<label for="sel1" class="">Amount:</label>
<input type="text" name="amount" class="form-control" value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount'] ?>"Placeholder="Enter Amount" required>
<input type="hidden" name="firstname" value="paysquare">
<input type="hidden" name="email" value="paysquare">
<input type="hidden" name="productinfo" value="recharge">
<br><br>
<?php if(!$hash) { ?>
<button type="submit" class="form-control" value="Submit" name="submit"/>Submit</button>
<?php } ?>
</form>
</div>
<div></div>
success page
<?php
$status=$_POST["status"];
$firstname=$_POST["firstname"];
$txnid=$_POST["txnid"];
$posted_hash=$_POST["hash"];
$key=$_POST["key"];
$productinfo=$_POST["productinfo"];
$email=$_POST["email"];
$amount = $_POST["amount"];
$opt=$_SESSION["opt"];
$salt="eCwWELxi";
If (isset($_POST["additionalCharges"])) {
$additionalCharges=$_POST["additionalCharges"];
$retHashSeq = $additionalCharges.'|'.$salt.'|'.$status.'|||||||||'.$udf2.'|'.$udf1.'|'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
}
else {
$retHashSeq = $salt.'|'.$status.'|||||||||'.$udf2.'|'.$udf1.'|'.$email.'|'.$firstname.'|'.$productinfo.'|'.$amount.'|'.$txnid.'|'.$key;
}
$hash = hash("sha512", $retHashSeq);
if ($hash != $posted_hash) {
echo "Transaction has been tampered. Please try again";
}
else {
$number = $_POST["phone"];
if(empty($opt)){
echo"select operator";
exit;
}
if(empty($number)){
echo"enter mobile number";
exit;
}
if(empty($amount)){
echo"enter amount";
exit;
}
$api_token = "myapi";
$ch = curl_init();
$timeout = 60;
$myurl = "https://www.pay2all.in/web-api/paynow?api_token=$api_token&provider_id=$opt&number=$number&amount=$amount";
curl_setopt ($ch, CURLOPT_URL, $myurl);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$maindata = json_decode($file_contents, true);
$status = $maindata['status'];
$message = $maindata['message'];
$payid = $maindata['payid'];
echo"Payid: $payid";
echo"<br/>";
echo"transaction Id: $txnid";
echo"<br/>";
echo"Recharge Status: $status";
echo"<br/>";
echo"Description is: $message";
}exit;
?>
您创建的标签对象引用和要添加到框架的引用是不同的。编辑如下,然后再次检查。
CoreBrightness
答案 1 :(得分:0)
您在JLabel
中保留了Jlabel
个对象引用,它应该是JLabel
JFrame frm = new JFrame("frame");
JLabel label = new JLabel("test text");
frm.add(label);
答案 2 :(得分:0)
Eclipse因为您的代码段中存在两个问题而抱怨:
Jlabel
包中没有swing
个类。有一个叫JLabel
而不是。{/ li>
jlab
的变量。有一个叫做'label`而不是。<强>替换强>
Jlabel label = new JLabel("test text");
frm.add(jlab);
<强>与强>
JLabel label = new JLabel("test text");
frm.add(label);